/*
 * Landing Page Editor Styles
 * MailerLite-inspired visual editor
 */

/* ==========================================================================
   Main Layout
   ========================================================================== */

.landing-editor {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background-color: #f8fafc;
}

.editor-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ==========================================================================
   Top Bar
   ========================================================================== */

.editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  gap: 1rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Sidebar expand button (hidden by default, shown when sidebar is collapsed) */
.sidebar-expand-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  color: #64748b;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-expand-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.sidebar-collapsed .sidebar-expand-btn {
  display: flex;
}

.topbar-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  color: #64748b;
  border-radius: 0.5rem;
  transition: all 0.15s ease;
}

.topbar-back:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.device-toggles {
  display: flex;
  background: #f1f5f9;
  border-radius: 0.5rem;
  padding: 0.25rem;
}

.device-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  color: #64748b;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  background: transparent;
}

.device-toggle:hover {
  color: #1e293b;
}

.device-toggle.active {
  background: white;
  color: #3b82f6;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

/* ==========================================================================
   Sidebar - Block Library
   ========================================================================== */

.editor-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: width 0.2s ease;
}

.editor-sidebar.collapsed {
  width: 0;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  color: #64748b;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  background: transparent;
}

.sidebar-toggle:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

/* Block Categories */
.block-category {
  margin-bottom: 0.5rem;
}

.category-header {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: #f8fafc;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  gap: 0.5rem;
}

.category-header:hover {
  background: #f1f5f9;
}

.category-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  color: #64748b;
}

.category-icon svg {
  width: 1rem;
  height: 1rem;
}

.category-name {
  flex: 1;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
}

.category-chevron {
  color: #9ca3af;
  transition: transform 0.2s ease;
}

.category-header[aria-expanded="true"] .category-chevron {
  transform: rotate(180deg);
}

/* Blocks inside category */
.category-blocks {
  display: none;
  padding: 0.5rem 0 0.5rem 1.75rem;
}

.category-header[aria-expanded="true"] + .category-blocks,
.block-category.expanded .category-blocks {
  display: block;
}

.library-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.25rem;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.library-block:hover {
  background: #eff6ff;
  border-color: #3b82f6;
}

.block-name {
  font-size: 0.75rem;
  color: #4b5563;
}

.block-add-icon {
  color: #9ca3af;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.library-block:hover .block-add-icon {
  opacity: 1;
  color: #3b82f6;
}

/* ==========================================================================
   Canvas Area
   ========================================================================== */

.editor-canvas {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f1f5f9;
}

.editor-canvas > * {
  width: 100%;
  max-width: 1200px;
}

/* Empty State */
.empty-canvas {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  border: 2px dashed #e2e8f0;
  border-radius: 0.75rem;
  background: white;
  text-align: center;
}

.empty-canvas.hidden {
  display: none;
}

.empty-canvas-content {
  padding: 2rem;
}

/* ==========================================================================
   Block Wrapper & Controls
   ========================================================================== */

.block-wrapper {
  position: relative;
  background: white;
  margin-bottom: 0;
  transition: all 0.15s ease;
}

.block-wrapper:hover {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

.block-wrapper.is-dragging {
  opacity: 0.5;
}

.block-wrapper.sortable-ghost {
  opacity: 0.4;
  background: #dbeafe;
}

.block-wrapper.sortable-chosen {
  box-shadow: 0 10px 25px -5px rgb(0 0 0 / 0.2);
}

/* Block controls */
.block-controls {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
}

.block-wrapper:hover .block-controls {
  opacity: 1;
  pointer-events: auto;
}

.block-control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

.block-control-btn:hover {
  background: #f8fafc;
  color: #1e293b;
  border-color: #cbd5e1;
}

.block-control-btn--drag {
  cursor: grab;
}

.block-control-btn--drag:active {
  cursor: grabbing;
}

.block-control-btn--delete:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

/* Right-side controls */
.block-controls--right {
  left: auto;
  right: 0.5rem;
}

/* ==========================================================================
   Save Indicator
   ========================================================================== */

.save-indicator {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.1);
  font-size: 0.8125rem;
  color: #64748b;
  z-index: 50;
}

.save-indicator.hidden {
  display: none;
}

.save-text {
  display: none;
}

.save-indicator.saving .save-saving-text {
  display: inline;
  color: #ca8a04;
}

.save-indicator.saved .save-saved-text {
  display: inline;
  color: #16a34a;
}

.save-indicator.error .save-error-text {
  display: inline;
  color: #dc2626;
}

/* ==========================================================================
   Editor Modals (Image, Video, Link, Array)
   ========================================================================== */

.editor-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.editor-modal.hidden {
  display: none;
}

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

.editor-modal-content {
  position: relative;
  background: white;
  padding: 1.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
  width: 100%;
  max-width: 400px;
  margin: 1rem;
  max-height: 90vh;
  overflow-y: auto;
}

.editor-modal-content--large {
  max-width: 600px;
}

.image-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  border: 2px dashed #e2e8f0;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.image-upload-zone:hover {
  border-color: #3b82f6;
  background: #eff6ff;
}

/* Array/List Editor Styles */
.array-items-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.array-item {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
}

.array-item-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.array-item-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
}

.array-item-input:focus {
  outline: none;
  border-color: #3b82f6;
  ring: 2px;
  ring-color: rgba(59, 130, 246, 0.3);
}

.array-item-textarea {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  min-height: 60px;
  resize: vertical;
}

.array-item-textarea:focus {
  outline: none;
  border-color: #3b82f6;
}

.array-item-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  color: #9ca3af;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.array-item-delete:hover {
  color: #dc2626;
  background: #fef2f2;
}

/* ==========================================================================
   Inline Editing
   ========================================================================== */

[data-editable] {
  cursor: text;
  transition: all 0.15s ease;
  border-radius: 0.25rem;
  position: relative;
}

[data-editable]:hover {
  outline: 2px dashed #93c5fd;
  outline-offset: 2px;
}

[data-editable]:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  background-color: rgba(255, 255, 255, 0.9);
}

/* Override for editable text inside CTA buttons - keep transparent background */
a[data-link-field] [data-editable]:focus,
button [data-editable]:focus,
[role="button"] [data-editable]:focus {
  background-color: transparent;
  outline: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

/* Override for editable text on dark backgrounds - common Tailwind dark bg classes */
.bg-slate-900 [data-editable]:focus,
.bg-slate-800 [data-editable]:focus,
.bg-slate-700 [data-editable]:focus,
.bg-gray-900 [data-editable]:focus,
.bg-gray-800 [data-editable]:focus,
.bg-gray-700 [data-editable]:focus,
.bg-zinc-900 [data-editable]:focus,
.bg-zinc-800 [data-editable]:focus,
.bg-neutral-900 [data-editable]:focus,
.bg-neutral-800 [data-editable]:focus,
.bg-black [data-editable]:focus,
[class*="bg-gradient-"] [data-editable]:focus {
  background-color: transparent;
  outline: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

/* Override for sections with inline colored backgrounds (CTA blocks, etc.) */
.cta-simple [data-editable]:focus,
.cta-urgency [data-editable]:focus,
section[style*="background-color"] [data-editable].text-white:focus,
section[style*="background-color"] .text-white [data-editable]:focus,
section[style*="background-color"] [data-editable][class*="text-white"]:focus {
  background-color: transparent;
  outline: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

/* Override for any element with inline background-color and white text */
[style*="background-color"].text-white [data-editable]:focus,
[style*="background-color"] .text-white [data-editable]:focus,
div[style*="background-color"] [data-editable]:focus,
span[style*="background-color"] [data-editable]:focus {
  background-color: transparent;
  outline: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

[data-editable][contenteditable="true"] {
  min-height: 1em;
}

/* Placeholder for empty editable */
[data-editable]:empty::before {
  content: attr(data-placeholder);
  color: #94a3b8;
  font-style: italic;
}

/* ==========================================================================
   Hidden/Delayed blocks
   ========================================================================== */

.block-wrapper--hidden {
  opacity: 0.5;
}

.block-wrapper--hidden::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(0, 0, 0, 0.03) 10px,
    rgba(0, 0, 0, 0.03) 20px
  );
  pointer-events: none;
}

.block-wrapper--delayed::before {
  content: "Delayed";
  position: absolute;
  top: 0.5rem;
  right: 3.5rem;
  padding: 0.125rem 0.5rem;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 0.25rem;
  z-index: 10;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
  .editor-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .editor-sidebar.open {
    transform: translateX(0);
  }

  .editor-canvas {
    padding: 1rem;
  }
}

/* Scrollbar */
.sidebar-content::-webkit-scrollbar,
.editor-canvas::-webkit-scrollbar {
  width: 8px;
}

.sidebar-content::-webkit-scrollbar-track,
.editor-canvas::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb,
.editor-canvas::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover,
.editor-canvas::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}
