/* ==========================================================
   Edit Mode — Photo swap preview tool
   (Prototype only, removed before Shopify migration)
   ========================================================== */

/* Toggle button (top-right, always visible) */
#em-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  background: #1a1a1a;
  color: #fafaf7;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 10px 18px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

#em-toggle:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}

.em-active #em-toggle {
  background: #fb923c;
  color: #1a1a1a;
  border-color: #fb923c;
}

#em-toggle .em-icon {
  font-size: 14px;
}

/* "View changes" floating button */
#em-view-changes {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9998;
  background: #fb923c;
  color: #1a1a1a;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  display: none;
  align-items: center;
  gap: 8px;
}

#em-view-changes.em-visible {
  display: inline-flex;
  animation: emPulseIn 0.3s cubic-bezier(0.2, 0, 0.2, 1);
}

#em-changes-count {
  background: #1a1a1a;
  color: #fb923c;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

@keyframes emPulseIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Edit mode active: images get visible affordances */
body.em-active img {
  outline: 2px dashed rgba(251, 146, 60, 0.7);
  outline-offset: 4px;
  cursor: pointer;
  transition: outline-color 0.2s ease, box-shadow 0.2s ease;
}

body.em-active img:hover {
  outline-color: rgba(251, 146, 60, 1);
  box-shadow: 0 0 0 4px rgba(251, 146, 60, 0.15);
}

body.em-active img.em-drag-over {
  outline-color: #22c55e;
  outline-style: solid;
  box-shadow: 0 0 0 8px rgba(34, 197, 94, 0.18);
}

body.em-active img.em-swapped {
  outline-color: #22c55e;
  outline-style: solid;
}

body.em-active img.em-loading {
  opacity: 0.4;
  filter: blur(2px);
}

/* Don't apply edit affordances to images inside the modal */
body.em-active #em-modal img {
  outline: none !important;
  cursor: default !important;
  box-shadow: none !important;
}
body.em-active #em-modal img:hover {
  outline: none !important;
  box-shadow: none !important;
}

/* ==========================================================
   Text editing affordances
   ========================================================== */

body.em-active [data-em-text-id] {
  outline: 1px dashed rgba(59, 130, 246, 0.4);
  outline-offset: 6px;
  border-radius: 2px;
  cursor: text;
  transition: outline-color 0.15s ease, background 0.15s ease;
  position: relative;
}

body.em-active [data-em-text-id]:hover {
  outline-color: rgba(59, 130, 246, 0.7);
  background: rgba(59, 130, 246, 0.03);
}

body.em-active [data-em-text-id].em-text-focused {
  outline: 2px solid #3b82f6 !important;
  background: rgba(59, 130, 246, 0.06);
}

body.em-active [data-em-text-id].em-text-edited {
  outline-color: #22c55e;
  outline-style: solid;
}

body.em-active [data-em-text-id].em-text-edited:hover {
  outline-color: #16a34a;
}

[data-em-text-id]:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 6px;
}

/* Hide outline on text elements inside the edit modal */
body.em-active #em-modal [data-em-text-id],
body.em-active #em-modal [data-em-text-id]:hover {
  outline: none !important;
  background: transparent !important;
  cursor: default !important;
}

/* ==========================================================
   Changes modal — text edit visualization
   ========================================================== */

.em-modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e3dc;
  padding-bottom: 12px;
}

.em-tab {
  background: transparent;
  border: 1px solid #e5e3dc;
  border-radius: 999px;
  padding: 6px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: #4a4a4a;
  cursor: pointer;
  transition: all 0.15s ease;
}

.em-tab:hover {
  border-color: #1a1a1a;
  color: #1a1a1a;
}

.em-tab-active {
  background: #1a1a1a;
  color: #fafaf7;
  border-color: #1a1a1a;
}

.em-section-h {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #8a8a85;
  margin: 24px 0 12px;
}

.em-section-h:first-child {
  margin-top: 0;
}

.em-change-text {
  display: block;
  grid-template-columns: unset;
}

.em-text-diff {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 12px 0;
}

@media (min-width: 600px) {
  .em-text-diff { grid-template-columns: 1fr 1fr; }
}

.em-text-before,
.em-text-after {
  background: #f2f0ea;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.em-text-after {
  background: rgba(34, 197, 94, 0.08);
  border-left: 3px solid #22c55e;
}

.em-text-before {
  border-left: 3px solid #cbcbc4;
  color: #4a4a4a;
}

.em-text-label {
  display: block;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #8a8a85;
  margin-bottom: 6px;
}

.em-text-before p,
.em-text-after p {
  margin: 0;
  word-break: break-word;
}

/* Help text overlay when entering edit mode (first time) */
body.em-active::before {
  content: '📝 文章は青枠をクリックで編集 ／ 📷 写真はクリックまたはドラッグ＆ドロップで差し替え';
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 9997;
  background: #1a1a1a;
  color: #fafaf7;
  padding: 10px 16px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  max-width: 280px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: emFadeInOut 6s ease forwards;
  pointer-events: none;
}

@keyframes emFadeInOut {
  0% { opacity: 0; transform: translateY(-10px); }
  10% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); pointer-events: none; }
}

/* ==========================================================
   Changes modal
   ========================================================== */

#em-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
}

#em-modal.em-modal-open {
  display: block;
}

.em-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.em-modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, 92vw);
  max-height: 88vh;
  background: #fafaf7;
  color: #1a1a1a;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.em-modal-header {
  padding: 20px 28px;
  border-bottom: 1px solid #e5e3dc;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.em-modal-header h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 24px;
  font-weight: 400;
  margin: 0;
}

.em-modal-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: #4a4a4a;
  cursor: pointer;
  padding: 4px 12px;
}

.em-modal-close:hover {
  color: #1a1a1a;
}

.em-modal-body {
  padding: 24px 28px 28px;
  overflow-y: auto;
  flex: 1;
}

.em-modal-intro {
  font-size: 14px;
  color: #4a4a4a;
  line-height: 1.6;
  margin-bottom: 24px;
  padding: 14px 16px;
  background: #f2f0ea;
  border-radius: 8px;
  border-left: 3px solid #fb923c;
}

.em-empty {
  text-align: center;
  color: #8a8a85;
  padding: 40px 20px;
  font-size: 14px;
}

#em-changes-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.em-change-item {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 16px;
  padding: 16px;
  background: white;
  border: 1px solid #e5e3dc;
  border-radius: 12px;
}

.em-change-preview {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  background: #f2f0ea;
}

.em-change-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.em-change-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.em-change-page {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a8a85;
  margin: 0;
}

.em-change-files {
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
  color: #1a1a1a;
}

.em-change-files code {
  background: #f2f0ea;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 11px;
}

.em-arrow {
  display: block;
  color: #8a8a85;
  font-size: 12px;
  margin: 4px 0;
}

.em-size {
  color: #8a8a85;
  font-size: 11px;
  margin-left: 4px;
}

.em-undo {
  align-self: flex-start;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
  color: #8a8a85;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  border-bottom: 1px solid #8a8a85;
}

.em-undo:hover {
  color: #1a1a1a;
  border-color: #1a1a1a;
}

.em-modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid #e5e3dc;
}

.em-btn-primary {
  background: #1a1a1a;
  color: #fafaf7;
  padding: 12px 24px;
  border: none;
  border-radius: 999px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  cursor: pointer;
  flex: 1;
}

.em-btn-primary:hover {
  opacity: 0.85;
}

.em-btn-danger {
  background: transparent;
  color: #8a8a85;
  padding: 12px 20px;
  border: 1px solid #e5e3dc;
  border-radius: 999px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.em-btn-danger:hover {
  color: #1a1a1a;
  border-color: #1a1a1a;
}

/* Hide edit mode UI when printing */
@media print {
  #em-toggle,
  #em-view-changes,
  #em-modal {
    display: none !important;
  }
}
