/**
 * Edit Mode Overlay Styles
 * Inline editing styles for Cloudflare Pages CMS
 */

/* ============================================
   Edit Mode Floating Badge
   ============================================ */
.edit-mode-badge {
  position: fixed;
  top: 16px;
  left: 16px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: white;
  padding: 10px 16px;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 500;
  z-index: 999999;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.1);
  opacity: 0.95;
  transition: all 0.2s ease;
  font-family: inherit;
  cursor: default;
  backdrop-filter: blur(10px);
}

.edit-mode-badge:hover {
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.edit-mode-badge__dot {
  width: 8px;
  height: 8px;
  background: var(--accent-color, var(--secondary-color, #00B4D8));
  border-radius: 50%;
  animation: editPulse 2s ease-in-out infinite;
}

@keyframes editPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.9); }
}

.edit-mode-badge__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  padding-left: 10px;
  border-left: 1px solid rgba(255,255,255,0.3);
}

.edit-mode-badge__btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.edit-mode-badge__btn:hover {
  background: rgba(255,255,255,0.25);
  transform: scale(1.1);
}

.edit-mode-badge__btn--danger:hover {
  background: #ef4444;
}

.edit-mode-badge__btn svg {
  width: 14px;
  height: 14px;
}

/* ============================================
   Editable Element Highlights
   ============================================ */
body.edit-mode [data-edit] {
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
}

body.edit-mode [data-edit]:hover {
  outline: 3px dashed var(--accent-color, var(--secondary-color, #00B4D8));
  outline-offset: 6px;
  box-shadow: 0 0 0 3px rgba(0, 180, 216, 0.15);
}

/* Label tooltip on hover */
body.edit-mode [data-edit]::after {
  content: attr(data-edit-label);
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-color, #059669);
  color: white;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  white-space: nowrap;
  z-index: 10000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

body.edit-mode [data-edit]:hover::after {
  opacity: 1;
}

/* ============================================
   Edit Panel (slides from right)
   ============================================ */
.edit-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 90vw;
  height: 100vh;
  background: white;
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 999998;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  font-family: inherit;
}

.edit-panel.open {
  transform: translateX(0);
}

.edit-panel__header {
  padding: 20px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
}

.edit-panel__title {
  font-size: 15px;
  font-weight: 600;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 10px;
}

.edit-panel__title-icon {
  width: 32px;
  height: 32px;
  background: var(--primary-color, #059669);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-panel__close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  transition: all 0.2s ease;
}

.edit-panel__close:hover {
  background: #e5e7eb;
  color: #1f2937;
}

.edit-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.edit-panel__footer {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: #fafbfc;
}

/* ============================================
   Form Elements
   ============================================ */
.edit-field {
  margin-bottom: 20px;
}

.edit-field__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #1f2937;
  margin-bottom: 8px;
}

.edit-field__sublabel {
  font-size: 12px;
  color: #6b7280;
  font-weight: 400;
  margin-left: 4px;
}

.edit-field__input,
.edit-field__textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  color: #1f2937;
  transition: all 0.2s ease;
  font-family: inherit;
  background: white;
  box-sizing: border-box;
}

.edit-field__input:focus,
.edit-field__textarea:focus {
  outline: none;
  border-color: var(--primary-color, #059669);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}

.edit-field__textarea {
  min-height: 150px;
  max-height: 400px;
  resize: vertical;
  line-height: 1.6;
}

/* Textarea for short text (titles, subtitles) */
.edit-field__textarea--text {
  min-height: 80px;
  max-height: 200px;
}

/* Ensure inputs are readable */
.edit-field__input {
  min-height: 48px;
  line-height: 1.5;
}

/* Long text inputs auto-expand */
.edit-field__input[type="text"] {
  white-space: normal;
  word-wrap: break-word;
}

.edit-field__number {
  width: 140px;
}

/* Language tabs */
.edit-lang-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: #f3f4f6;
  padding: 4px;
  border-radius: 8px;
}

.edit-lang-tab {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.edit-lang-tab.active {
  background: white;
  color: var(--primary-color, #059669);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ============================================
   Image Picker
   ============================================ */
.edit-image-picker {
  border: 2px dashed #e5e7eb;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  transition: all 0.2s ease;
}

.edit-image-picker:hover {
  border-color: var(--accent-color, var(--secondary-color, #00B4D8));
}

.edit-image-picker__current {
  margin-bottom: 12px;
}

.edit-image-picker__current img {
  max-width: 100%;
  max-height: 120px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.edit-image-library {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
  max-height: 280px;
  overflow-y: auto;
  padding: 4px;
}

/* Empty state for image library */
.edit-image-library__empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 12px;
  border: 2px dashed #e2e8f0;
}

.edit-image-library__empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  background: #e2e8f0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-image-library__empty-icon svg {
  width: 24px;
  height: 24px;
  color: #94a3b8;
}

.edit-image-library__empty-text {
  font-size: 14px;
  color: #64748b;
  margin: 0;
}

.edit-image-library__empty-hint {
  font-size: 12px;
  color: #94a3b8;
  margin: 8px 0 0;
}

/* Error state */
.edit-image-library__error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 30px 20px;
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  border-radius: 12px;
  border: 2px dashed #fecaca;
}

.edit-image-library__error-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, #fecaca 0%, #fca5a5 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-image-library__error-icon svg {
  width: 24px;
  height: 24px;
  color: #dc2626;
}

.edit-image-library__error-text {
  font-size: 14px;
  font-weight: 500;
  color: #dc2626;
  margin: 0;
}

.edit-image-library__item {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  position: relative;
  background: #f3f4f6;
}

.edit-image-library__item:hover {
  border-color: var(--accent-color, var(--secondary-color, #00B4D8));
}

.edit-image-library__item.selected {
  border-color: var(--primary-color, #059669);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.2);
}

.edit-image-library__item img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.edit-image-library__item.selected::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(5, 150, 105, 0.7);
}

.edit-image-library__item.selected::before {
  content: '\2713';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 24px;
  font-weight: bold;
  z-index: 1;
}

/* ============================================
   Buttons
   ============================================ */
.edit-btn {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}

.edit-btn--primary {
  background: var(--primary-color, #059669);
  color: white;
}

.edit-btn--primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.edit-btn--secondary {
  background: #f3f4f6;
  color: #1f2937;
}

.edit-btn--secondary:hover {
  background: #e5e7eb;
}

.edit-btn--success {
  background: var(--accent-color, var(--secondary-color, #00B4D8));
  color: white;
}

.edit-btn--success:hover {
  filter: brightness(1.1);
}

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

/* ============================================
   Admin Redirect Message (for lists)
   ============================================ */
.edit-admin-redirect {
  text-align: center;
  padding: 30px 20px;
}

.edit-admin-redirect__icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.edit-admin-redirect__icon svg {
  width: 32px;
  height: 32px;
  color: #6b7280;
}

.edit-admin-redirect__title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 8px;
}

.edit-admin-redirect__text {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 20px;
  line-height: 1.5;
}

.edit-admin-redirect__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--primary-color, #059669);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.edit-admin-redirect__btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.edit-admin-redirect__btn svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   Loading & Toast
   ============================================ */
.edit-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.edit-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary-color, #059669);
  border-radius: 50%;
  animation: editSpin 0.7s linear infinite;
}

@keyframes editSpin {
  to { transform: rotate(360deg); }
}

.edit-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  left: auto;
  padding: 12px 20px;
  background: #1f2937;
  color: white;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 999999;
  transform: translateX(20px);
  opacity: 0;
  transition: all 0.2s ease;
}

.edit-toast.show {
  transform: translateX(0);
  opacity: 1;
}

.edit-toast--success {
  background: #10b981;
}

.edit-toast--error {
  background: #ef4444;
}

/* ============================================
   Backdrop
   ============================================ */
.edit-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  z-index: 999997;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
}

.edit-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 480px) {
  .edit-panel {
    width: 100%;
    max-width: 100vw;
  }

  .edit-panel__body {
    padding: 16px;
  }

  .edit-panel__footer {
    padding: 12px 16px;
  }

  .edit-mode-badge {
    top: auto;
    bottom: 12px;
    left: 12px;
    padding: 8px 10px;
    gap: 0;
  }

  .edit-mode-badge > span:not(.edit-mode-badge__dot) {
    display: none;
  }

  .edit-mode-badge__actions {
    margin-left: 8px;
    padding-left: 8px;
  }

  .edit-image-library {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .edit-field__input,
  .edit-field__textarea {
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

/* ============================================
   Advantages Editor
   ============================================ */
.edit-advantages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-advantage-item {
  background: #f8f9fa;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.2s ease;
}

.edit-advantage-item.hidden {
  opacity: 0.5;
}

.edit-advantage-item__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.edit-advantage-item__icon {
  width: 40px;
  height: 40px;
  background: var(--primary-color, #059669);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  flex-shrink: 0;
}

.edit-advantage-item__title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
}

.edit-advantage-item__actions {
  display: flex;
  gap: 4px;
}

.edit-advantage-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(0,0,0,0.05);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.edit-advantage-btn:hover {
  background: var(--primary-color, #059669);
  color: white;
}

.edit-advantage-btn svg {
  width: 16px;
  height: 16px;
}

.edit-advantage-btn--toggle:hover {
  background: #6b7280;
}

/* Icon Picker */
.edit-icon-picker {
  display: flex;
  align-items: center;
  gap: 12px;
}

.edit-icon-preview {
  width: 48px;
  height: 48px;
  background: var(--primary-color, #059669);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
}

.edit-field__select {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  color: #1f2937;
  background: white;
  cursor: pointer;
}

.edit-field__select:focus {
  outline: none;
  border-color: var(--primary-color, #059669);
}

/* Toggle Switch */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.edit-toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.edit-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.edit-toggle__slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 24px;
}

.edit-toggle__slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.edit-toggle input:checked + .edit-toggle__slider {
  background-color: var(--primary-color, #059669);
}

.edit-toggle input:checked + .edit-toggle__slider:before {
  transform: translateX(20px);
}

/* Admin Link */
.edit-admin-link a:hover {
  color: var(--primary-color, #059669) !important;
}

/* ============================================
   Quill Editor in Edit Panel
   ============================================ */
.edit-quill-editor {
  background: white;
  border-radius: 8px;
  min-height: 150px;
}

.edit-quill-editor .ql-toolbar {
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  border-color: #e0e0e0;
  background: #f8f9fa;
}

.edit-quill-editor .ql-container {
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  border-color: #e0e0e0;
  font-size: 14px;
  min-height: 120px;
}

.edit-quill-editor .ql-editor {
  min-height: 120px;
  padding: 12px;
}

.edit-quill-editor .ql-editor p {
  margin-bottom: 0.5em;
}

/* ============================================
   Print: Hide edit elements
   ============================================ */
@media print {
  .edit-mode-badge,
  .edit-panel,
  .edit-backdrop,
  .edit-toast {
    display: none !important;
  }
}
