.cms-editing [data-cms-key]:not(.footer-bg-img):not(.footer-logo-img):not(.logo-img) {
  position: relative;
}

body.cms-logged-in [data-cms-type="image"]:not(.cms-no-edit):not(.footer-bg-img):not(.footer-logo-img):not(.logo-img),
body.cms-logged-in [data-cms-key][data-cms-type="image"]:not(.cms-no-edit):not(.footer-bg-img):not(.footer-logo-img):not(.logo-img) {
  position: relative;
  cursor: pointer;
}

body.cms-logged-in [data-cms-type="image"]:not(.cms-no-edit):not(.footer-bg-img):not(.footer-logo-img):not(.logo-img):hover,
body.cms-logged-in [data-cms-key][data-cms-type="image"]:not(.cms-no-edit):not(.footer-bg-img):not(.footer-logo-img):not(.logo-img):hover {
  outline: 2px dashed #c8161d;
  outline-offset: 2px;
}

.cms-editing [data-cms-key]:not([data-cms-type="image"]):not(.cms-no-edit) {
  cursor: pointer;
}

.cms-editing [data-cms-key]:not([data-cms-type="image"]):not(.cms-no-edit):hover {
  outline: 2px dashed #c8161d;
  outline-offset: 2px;
}

body.cms-logged-in [data-cms-type="image"]:not(.cms-no-edit)::after,
body.cms-logged-in [data-cms-key][data-cms-type="image"]:not(.cms-no-edit)::after {
  content: attr(data-cms-label);
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 5;
  padding: 2px 8px;
  background: rgba(200, 22, 29, 0.92);
  color: #fff;
  font-size: 11px;
  line-height: 1.4;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

body.cms-logged-in.zh-upload-hint [data-cms-type="image"]:not(.cms-no-edit)::after,
body.cms-logged-in.zh-upload-hint [data-cms-key][data-cms-type="image"]:not(.cms-no-edit)::after {
  content: attr(data-cms-label) ' · 双击上传';
}

body.cms-logged-in.en-upload-hint [data-cms-type="image"]:not(.cms-no-edit)::after,
body.cms-logged-in.en-upload-hint [data-cms-key][data-cms-type="image"]:not(.cms-no-edit)::after {
  content: attr(data-cms-label) ' · Double-click to upload';
}

body.cms-logged-in.zh-upload-hint [data-cms-type="image"]:not(.cms-no-edit)[data-cms-size-label]::after,
body.cms-logged-in.zh-upload-hint [data-cms-key][data-cms-type="image"]:not(.cms-no-edit)[data-cms-size-label]::after {
  content: attr(data-cms-label) ' · ' attr(data-cms-size-label) ' · 双击上传';
}

body.cms-logged-in.en-upload-hint [data-cms-type="image"]:not(.cms-no-edit)[data-cms-size-label]::after,
body.cms-logged-in.en-upload-hint [data-cms-key][data-cms-type="image"]:not(.cms-no-edit)[data-cms-size-label]::after {
  content: attr(data-cms-label) ' · ' attr(data-cms-size-label) ' · Double-click to upload';
}

body.cms-logged-in [data-cms-type="image"]:not(.cms-no-edit):hover::after,
body.cms-logged-in [data-cms-key][data-cms-type="image"]:not(.cms-no-edit):hover::after {
  opacity: 1;
}

.cms-editing [data-cms-key]:not([data-cms-type="image"]):not(.cms-no-edit)::after {
  content: attr(data-cms-label);
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 5;
  padding: 2px 8px;
  background: rgba(200, 22, 29, 0.92);
  color: #fff;
  font-size: 11px;
  line-height: 1.4;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.cms-editing [data-cms-key]:not([data-cms-type="image"]):not(.cms-no-edit):hover::after {
  opacity: 1;
}

.cms-no-edit {
  cursor: default !important;
}

body.cms-editing .cms-nav-suspended,
body.cms-logged-in .cms-nav-suspended {
  pointer-events: none;
  cursor: default;
}

body.cms-editing .cms-nav-suspended img[data-cms-key],
body.cms-logged-in .cms-nav-suspended img[data-cms-key],
body.cms-editing .cms-nav-suspended [data-cms-type="image"],
body.cms-logged-in .cms-nav-suspended [data-cms-type="image"] {
  pointer-events: auto;
  cursor: pointer;
}

.cms-uploading {
  position: relative;
}

.cms-uploading::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(255, 255, 255, 0.65);
}

.cms-uploading::after {
  content: 'Uploading…';
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 7;
  transform: translate(-50%, -50%);
  padding: 6px 12px;
  background: rgba(34, 34, 34, 0.88);
  color: #fff;
  font-size: 12px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 1;
}

body.cms-logged-in.zh-upload-hint .cms-uploading::after {
  content: '上传中…';
}

.cms-toolbar {
  position: fixed;
  top: 88px;
  right: 16px;
  bottom: auto;
  left: auto;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: rgba(34, 34, 34, 0.92);
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  font-size: 12px;
  line-height: 1.35;
  max-width: min(280px, calc(100vw - 32px));
  pointer-events: none;
}

@media (max-width: 768px) {
  .cms-toolbar {
    top: 118px;
    right: 12px;
    left: auto;
    max-width: calc(100vw - 24px);
    font-size: 11px;
    padding: 6px 10px;
  }
}

.cms-toolbar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  flex-shrink: 0;
}

.cms-modal {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.cms-modal.is-open {
  display: flex;
}

.cms-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.cms-modal-dialog {
  position: relative;
  width: min(520px, 100%);
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
}

.cms-modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #222;
}

.cms-modal-key {
  font-size: 12px;
  color: #888;
  margin-bottom: 12px;
  word-break: break-all;
}

.cms-modal-textarea {
  width: 100%;
  min-height: 140px;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
}

.cms-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.cms-modal-btn {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}

.cms-modal-btn.primary {
  background: #c8161d;
  color: #fff;
}

.cms-modal-btn.secondary {
  background: #f2f2f2;
  color: #333;
}

.cms-modal-status {
  margin-top: 10px;
  font-size: 13px;
  color: #c8161d;
}

.cms-hidden-input {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  padding: 0;
  margin: 0;
  pointer-events: none;
}

.cms-hidden-input.cms-file-input-active {
  width: 100%;
  height: 100%;
  opacity: 0.001;
  clip: auto;
  pointer-events: auto;
  z-index: 99999;
}

.cms-image-target img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

img.cms-image-target.cms-has-image:not(.page-hero-img):not(.carousel-slide-img) {
  width: 100%;
  height: auto;
  object-fit: contain;
}

.logo-img.cms-image-target,
.logo-img.cms-applied {
  width: auto;
  height: 34px;
  max-width: 204px;
  object-fit: contain;
  display: block;
}

.footer-logo-img.cms-image-target,
.footer-logo-img.cms-applied {
  width: auto;
  height: 34px;
  max-width: 208px;
  object-fit: contain;
  display: block;
}

.footer-bg-img.cms-image-target,
.footer-bg-img.cms-applied {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: left bottom;
  pointer-events: none;
  z-index: 0;
}

@media (max-width: 768px) {
  .logo-img.cms-image-target,
  .logo-img.cms-applied {
    height: 30px;
    max-width: 141px;
  }

  .footer-logo-img.cms-image-target,
  .footer-logo-img.cms-applied {
    height: 38px;
    max-width: 205px;
  }
}

.page-hero .page-hero-img.cms-image-target.cms-has-image,
.page-hero .cms-image-target img,
.page-hero-img.cms-applied {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

.about-gallery img.about-gallery-img.cms-image-target.cms-has-image,
.about-gallery-img.cms-applied {
  width: 100%;
  max-width: 1196px;
  height: auto;
  aspect-ratio: 1196 / 793;
  object-fit: contain;
  background: #fff;
}

.carousel-slide.cms-has-image img.carousel-slide-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.index-about-mobile img.cms-applied,
.index-about-mobile img.cms-has-image,
.index-about-mobile .cms-image-target.cms-has-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.index-about-desktop img.cms-applied,
.index-about-desktop img.cms-has-image,
.index-about-desktop .cms-image-target.cms-has-image img,
.about-section--desktop .index-about-desktop-img,
.about-section--desktop img.cms-applied,
.about-section--desktop img.cms-has-image {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.feature-banner .cms-image-target.cms-has-image,
.feature-banner .cms-image-target.cms-has-image img,
.feature-banner img.cms-applied,
.feature-banner img.cms-has-image,
.cert-grid .cms-image-target.cms-has-image {
  padding: 0;
  background: #fff;
}

.feature-banner .cms-image-target.cms-has-image img,
.feature-banner img.cms-applied,
.feature-banner img.cms-has-image,
.cert-grid .cms-image-target.cms-has-image img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* Image upload editor */
.cms-image-editor {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.cms-image-editor.is-open {
  display: flex;
}

body.cms-image-editor-open {
  overflow: hidden;
}

.cms-image-editor-dialog {
  position: relative;
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #fff;
  border-radius: 6px;
  padding: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
  z-index: 1;
}

.cms-image-editor-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  color: #222;
}

.cms-image-editor-meta {
  margin: 0 0 14px;
  font-size: 13px;
  color: #666;
}

.cms-image-editor-stage-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.cms-image-editor-stage {
  position: relative;
  overflow: hidden;
  background: #f3f3f3;
  user-select: none;
  touch-action: none;
}

.cms-image-editor-stage img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cms-editor-crop {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid #c8161d;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  cursor: move;
}

.cms-editor-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #c8161d;
  border: 2px solid #fff;
  border-radius: 2px;
  box-sizing: border-box;
}

.cms-editor-handle-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.cms-editor-handle-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.cms-editor-handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.cms-editor-handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }

.cms-image-editor-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.cms-image-editor-preview-label {
  font-size: 12px;
  color: #888;
  flex-shrink: 0;
}

.cms-image-editor-preview {
  display: block;
  border: 1px solid #e8e8e8;
  background: #fafafa;
  max-width: 160px;
  max-height: 120px;
}

.cms-image-editor-tools {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.cms-image-editor-tool {
  border: 1px solid #ddd;
  background: #f7f7f7;
  color: #333;
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.cms-image-editor-tool.is-active {
  border-color: #c8161d;
  background: #fff5f5;
  color: #c8161d;
  font-weight: 600;
}

.cms-image-editor-hint {
  margin: 0 0 14px;
  font-size: 12px;
  color: #888;
  line-height: 1.6;
}
