/* Newsletter Editor Styles */
:root {
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-text: #1e293b;
  --color-bg: #f8fafc;
  --color-border: #e2e8f0;
}

.newsletter-editor {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

@media (min-width: 768px) {
  .newsletter-editor {
    flex-direction: row;
  }
}

/* Sidebar */
.newsletter-sidebar {
  width: 100%;
  flex-shrink: 0;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 768px) {
  .newsletter-sidebar {
    width: 280px;
    border-bottom: none;
    border-right: 1px solid #e2e8f0;
  }
}

.newsletter-sidebar__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
}

.newsletter-sidebar__brand-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: #3b82f6;
}

.newsletter-sidebar__section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.newsletter-sidebar__section-title {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.688rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.newsletter-sidebar__buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.newsletter-sidebar__button {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: 2px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
}

.newsletter-sidebar__button--primary {
  background: #3b82f6;
  color: white;
}

.newsletter-sidebar__button--primary:hover {
  filter: brightness(0.95);
}

.newsletter-sidebar__button--secondary {
  border-color: #3b82f6;
  color: #3b82f6;
  background: transparent;
}

.newsletter-sidebar__button--secondary:hover {
  background: rgba(59, 130, 246, 0.1);
}

.newsletter-sidebar__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.newsletter-sidebar__action {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  font-size: 0.875rem;
  color: #64748b;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.newsletter-sidebar__action:hover {
  background: rgba(248, 250, 252, 0.7);
}

.newsletter-sidebar__export {
  margin-top: 0.5rem;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: white;
  color: var(--color-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  /* For link_to */
}

.newsletter-sidebar__export:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.newsletter-sidebar__send-btn {
  margin-top: 1rem;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  border-radius: 0.75rem;
  background: var(--color-primary);
  color: white !important;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.2);
}

.newsletter-sidebar__send-btn:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 8px -1px rgba(59, 130, 246, 0.3);
}

.newsletter-sidebar__hint {
  margin-top: auto;
  font-size: 0.75rem;
  color: #64748b;
}

/* Main Content */
.newsletter-main {
  flex: 1;
  display: flex;
  justify-content: center;
}

.newsletter-canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 64rem;
  margin: 1.25rem;
}

.newsletter-status {
  position: absolute;
  top: -0.75rem;
  left: 1.5rem;
  font-size: 0.75rem;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 9999px;
  padding: 0.25rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s;
}

.newsletter-status--saving {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: #eff6ff;
}

.newsletter-status--saving::before {
  content: "";
  width: 8px;
  height: 8px;
  border: 2px solid var(--color-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: newsletter-spin 0.8s linear infinite;
}

@keyframes newsletter-spin {
  to {
    transform: rotate(360deg);
  }
}

.newsletter-controls {
  position: absolute;
  top: -0.75rem;
  right: 1.5rem;
  display: flex;
  gap: 0.5rem;
}

.newsletter-control {
  padding: 0.375rem 1rem;
  border-radius: 9999px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.newsletter-control:hover {
  background: rgba(255, 255, 255, 0.6);
}

.newsletter-control[aria-pressed="true"] {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

/* Canvas */
.newsletter-canvas {
  background: white;
  border: 1px solid #e2e8f0;
  /* Email width simulation */
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  border-radius: 2px;
  padding: 24px;
  min-height: 600px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
}

.newsletter-canvas-inner {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Title Field */
.newsletter-title-field {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
  transition: all 0.2s;
}

.newsletter-title-field:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Blocks */
.newsletter-block {
  position: relative;
  border-radius: 0.75rem;
  border: 2px solid transparent;
  transition: all 0.2s;
  z-index: 0;
}

.newsletter-block:hover {
  border-color: #3b82f6;
}

.newsletter-block--dragging {
  opacity: 0.6;
}

.newsletter-block--grabbing {
  cursor: grabbing;
}

/* Drag Handle */
.newsletter-drag-handle {
  position: absolute;
  left: -28px;
  top: 0.75rem;
  width: 1.5rem;
  height: 2rem;
  border-radius: 0.375rem;
  border: 1px solid #e2e8f0;
  background: rgba(241, 245, 249, 0.7);
  color: #64748b;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: all 0.2s;
}

@media (min-width: 768px) {
  .newsletter-drag-handle {
    display: inline-grid;
  }
}

.newsletter-drag-handle:hover {
  background: #f1f5f9;
}

.newsletter-drag-handle svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* Block Controls */
.newsletter-block-controls {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 20;
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: auto;
}

.newsletter-block:hover .newsletter-block-controls {
  opacity: 1;
}

.newsletter-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid #e2e8f0;
  background: #f1f5f9;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s;
}

.newsletter-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

.newsletter-btn--edit:hover {
  background: rgba(59, 130, 246, 0.1);
}

.newsletter-btn--delete:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Paragraph Block */
.newsletter-paragraph {
  min-height: 2.5rem;
  padding: 4px 8px;
  /* Reduce padding to feel more like the final output */
  border-radius: 4px;
  background: transparent;
  transition: all 0.2s;
  /* WYSIWYG defaults */
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #111;
}

.newsletter-paragraph:focus {
  outline: none;
  box-shadow: 0 0 0 2px #3b82f6;
}

.newsletter-paragraph[data-placeholder]:empty:before {
  content: attr(data-placeholder);
  color: #94a3b8;
  opacity: 0.9;
}

/* Image Block */
.newsletter-image-upload {
  display: block;
  padding: 0.75rem;
}

.newsletter-file-input {
  display: none;
}

.newsletter-image-frame {
  border: 2px dashed #e2e8f0;
  border-radius: 0.5rem;
  min-height: 160px;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
}

.newsletter-image-frame:hover {
  border-color: #3b82f6;
}

.newsletter-image-frame--dragover {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.newsletter-upload-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: #64748b;
  font-size: 0.875rem;
  pointer-events: none;
}

.newsletter-upload-hint svg {
  width: 1.375rem;
  height: 1.375rem;
  opacity: 0.8;
}

.newsletter-image {
  max-width: 100%;
  height: auto;
  border-radius: 0.375rem;
  object-fit: cover;
}

/* Drop Marker */
.newsletter-drop-marker {
  height: 0.75rem;
  border: 2px dashed #3b82f6;
  border-radius: 0.375rem;
  margin: 0.25rem 0;
}

/* Hidden Elements (for preview mode) */
.newsletter-hidden {
  display: none !important;
}

/* Inline toolbar for paragraph formatting */
/* Inline toolbar for paragraph formatting */
.newsletter-inline-toolbar {
  position: absolute;
  top: -42px;
  /* sit above the block */
  left: 0;
  display: flex;
  gap: 2px;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.12s ease-in-out;

  /* New stylish look */
  background: #1e293b;
  /* Slate 800 */
  padding: 4px;
  border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  border: 1px solid #334155;
}

.newsletter-block:focus-within .newsletter-inline-toolbar {
  opacity: 1;
}

.newsletter-inline-toolbar__btn {
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  font-size: 13px;
  line-height: 1;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: #f1f5f9;
  /* Slate 100 */
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.1s;
}

.newsletter-inline-toolbar__btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.newsletter-inline-toolbar__btn[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.newsletter-inline-toolbar__select {
  height: 28px;
  padding: 0 6px;
  font-size: 13px;
  border-radius: 4px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #f1f5f9;
  cursor: pointer;
  outline: none;
  margin-right: 4px;
}

.newsletter-inline-toolbar__select:hover {
  background: rgba(255, 255, 255, 0.2);
}

.newsletter-inline-toolbar__select option {
  background: #1e293b;
  color: #f1f5f9;
}

/* Code editor for paragraph HTML */
.newsletter-code-editor {
  width: 100%;
  min-height: 140px;
  padding: 10px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  display: none;
}

.newsletter-code-editor--visible {
  display: block;
}

/* Headings preview inside editor only */
.newsletter-paragraph h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0.4rem 0;
}

.newsletter-paragraph h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0.35rem 0;
}

/* Link editor popover */
.newsletter-link-editor {
  position: absolute;
  z-index: 1000;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  padding: 8px;
  display: none;
  min-width: 260px;
}

.newsletter-link-editor--visible {
  display: block;
}

.newsletter-link-editor__row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.newsletter-link-editor__input {
  flex: 1;
}

/* Modal */
.newsletter-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.newsletter-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}

.newsletter-modal__dialog {
  position: relative;
  background: #fff;
  border-radius: 0.75rem;
  width: 100%;
  max-width: 480px;
  margin: 10vh auto 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  overflow: hidden;
}

.newsletter-modal__header {
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
}

.newsletter-modal__body {
  padding: 16px;
}

.newsletter-modal__footer {
  padding: 12px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid #e2e8f0;
}

/* Button Block */
.newsletter-button-wrapper {
  text-align: center;
  padding: 10px;
}

.newsletter-button {
  display: inline-block;
  padding: 10px 20px;
  background-color: #3b82f6;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 600;
  transition: background-color 0.2s;
}

.newsletter-button:hover {
  background-color: #2563eb;
}

.newsletter-button:focus {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

/* Divider Block */
.newsletter-divider-wrapper {
  padding: 20px 0;
}

.newsletter-divider {
  border: 0;
  border-top: 1px solid #e2e8f0;
  margin: 0;
}

/* Social Block */
.newsletter-social-wrapper {
  text-align: center;
  padding: 10px;
}

.newsletter-social-link {
  display: inline-block;
  margin: 0 8px;
  color: #64748b;
  text-decoration: none;
  transition: opacity 0.2s;
}

.newsletter-social-link:hover {
  opacity: 0.8;
}