.crm-ve-editor {
  --crm-ve-accent: #2563eb;
  --crm-ve-accent-light: rgba(37, 99, 235, 0.12);
  --crm-ve-surface: #ffffff;
  --crm-ve-surface-soft: #f6f8fb;
  --crm-ve-border: #d9e1ec;
  --crm-ve-border-strong: #b8c4d5;
  --crm-ve-text: #1e293b;
  --crm-ve-text-muted: #64748b;
  --crm-ve-danger: #dc2626;
  --crm-ve-success: #119c65;
  --crm-ve-radius: 16px;
  --crm-ve-toolbar-height: 44px;
  --crm-ve-btn-size: 30px;
  --crm-ve-btn-radius: 8px;
  --crm-ve-min-height: 160px;

  position: relative;
  width: 100%;
  flex: 1 1 auto;
  border: 1px solid var(--crm-ve-border);
  border-radius: var(--crm-ve-radius);
  background: var(--crm-ve-surface);
  color: var(--crm-ve-text);
  color-scheme: light;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.crm-ve-editor.is-focused {
  border-color: var(--crm-ve-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.crm-ve-editor.is-dragover {
  border-color: var(--crm-ve-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: var(--crm-ve-surface-soft);
}

.crm-ve-editor.is-readonly {
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.crm-ve-editor.is-readonly .crm-ve-toolbar,
.crm-ve-editor.is-readonly .crm-ve-image-toolbar,
.crm-ve-editor.is-readonly .crm-ve-resize-handle {
  display: none !important;
}

.crm-ve-editor.is-readonly .crm-ve-content {
  padding: 0;
  min-height: auto;
}

.crm-ve-editor.is-readonly .crm-ve-block {
  margin: 0;
}

.crm-ve-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--crm-ve-border);
  background: var(--crm-ve-surface-soft);
  border-radius: var(--crm-ve-radius) var(--crm-ve-radius) 0 0;
  min-height: var(--crm-ve-toolbar-height);
  user-select: none;
}

.crm-ve-toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--crm-ve-border);
  margin: 0 4px;
  flex-shrink: 0;
}

.crm-ve-toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--crm-ve-btn-size);
  height: var(--crm-ve-btn-size);
  border: none;
  border-radius: var(--crm-ve-btn-radius);
  background: transparent;
  color: var(--crm-ve-text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
  padding: 0;
  line-height: 1;
}

.crm-ve-toolbar-btn:hover {
  background: var(--crm-ve-accent-light);
  color: var(--crm-ve-accent);
}

.crm-ve-toolbar-btn.is-active {
  background: var(--crm-ve-accent-light);
  color: var(--crm-ve-accent);
}

.crm-ve-toolbar-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.crm-ve-toolbar-btn svg,
.crm-ve-toolbar-btn i {
  pointer-events: none;
}

.crm-ve-toolbar-btn i {
  display: block;
  font-size: 13px;
  line-height: 1;
}

.crm-ve-toolbar-btn svg {
  display: block;
  width: 14px;
  height: 14px;
}

.crm-ve-content {
  padding: 12px 16px;
  min-height: var(--crm-ve-min-height);
  outline: none;
  cursor: text;
}

.crm-ve-empty-actions {
  display: none;
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(var(--crm-ve-toolbar-height) + 56px);
  gap: 10px;
  flex-wrap: wrap;
  pointer-events: none;
}

.crm-ve-wrapper.is-empty .crm-ve-empty-actions {
  display: flex;
}

.crm-ve-quick-chip {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 11px;
  border: 1px dashed var(--crm-ve-border-strong);
  border-radius: 999px;
  background: var(--crm-ve-surface-soft);
  color: var(--crm-ve-text-muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1;
  pointer-events: none;
  cursor: pointer;
}

.crm-ve-quick-chip:hover {
  border-color: var(--crm-ve-accent);
  color: var(--crm-ve-accent);
  background: var(--crm-ve-accent-light);
}

.crm-ve-wrapper.is-empty .crm-ve-content[data-placeholder]::before,
.crm-ve-content-is-empty .crm-ve-content::before {
  content: attr(data-placeholder);
  color: var(--crm-ve-text-muted);
  pointer-events: none;
  position: absolute;
  top: calc(var(--crm-ve-toolbar-height) + 18px);
  left: 16px;
  right: 16px;
  opacity: 0.6;
}

.crm-ve-content:focus-visible {
  outline: none;
}

.crm-ve-block {
  margin: 0 0 8px;
}

.crm-ve-block:last-child {
  margin-bottom: 0;
}

.crm-ve-text-block {
  position: relative;
}

.crm-ve-text-block p {
  margin: 0 0 4px;
  min-height: 1.4em;
  line-height: 1.6;
  color: var(--crm-ve-text);
}

.crm-ve-content p {
  margin: 0 0 10px;
  min-height: 1.4em;
  line-height: 1.6;
  color: var(--crm-ve-text);
}

.crm-ve-content h1,
.crm-ve-content h2,
.crm-ve-content h3 {
  margin: 12px 0 8px;
  font-weight: 650;
  line-height: 1.3;
  color: var(--crm-ve-text);
}

.crm-ve-content h1 { font-size: 1.5em; }
.crm-ve-content h2 { font-size: 1.25em; }
.crm-ve-content h3 { font-size: 1.1em; }

.crm-ve-content blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--crm-ve-accent);
  background: var(--crm-ve-surface-soft);
  border-radius: 0 4px 4px 0;
  color: var(--crm-ve-text-muted);
}

.crm-ve-content ul,
.crm-ve-content ol {
  margin: 6px 0 12px;
  padding-left: 24px;
}

.crm-ve-content li {
  margin: 3px 0;
  line-height: 1.5;
}

.crm-ve-content a {
  color: var(--crm-ve-accent);
  text-decoration: underline;
}

.crm-ve-text-block p:last-child {
  margin-bottom: 0;
}

.crm-ve-text-block h1,
.crm-ve-text-block h2,
.crm-ve-text-block h3 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.3;
}

.crm-ve-text-block h1 { font-size: 1.5em; }
.crm-ve-text-block h2 { font-size: 1.25em; }
.crm-ve-text-block h3 { font-size: 1.1em; }

.crm-ve-text-block blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--crm-ve-accent);
  color: var(--crm-ve-text-muted);
  background: var(--crm-ve-surface-soft);
  border-radius: 0 4px 4px 0;
}

.crm-ve-text-block pre {
  margin: 8px 0;
  padding: 12px;
  background: #f1f5f9;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
}

.crm-ve-text-block pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.crm-ve-text-block code {
  padding: 2px 6px;
  background: #f1f5f9;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.875em;
  color: #7c3aed;
}

.crm-ve-text-block ul,
.crm-ve-text-block ol {
  margin: 4px 0;
  padding-left: 24px;
}

.crm-ve-text-block li {
  margin: 2px 0;
  line-height: 1.5;
}

.crm-ve-text-block a {
  color: var(--crm-ve-accent);
  text-decoration: underline;
}

.crm-ve-placeholder {
  color: var(--crm-ve-text-muted);
  pointer-events: none;
}

.crm-ve-image-block {
  display: flex;
  width: 100%;
  margin: 12px 0;
  position: relative;
}

.crm-ve-image-block[data-align="left"] {
  justify-content: flex-start;
}

.crm-ve-image-block[data-align="center"] {
  justify-content: center;
}

.crm-ve-image-block[data-align="right"] {
  justify-content: flex-end;
}

.crm-ve-image-figure {
  position: relative;
  width: var(--crm-ve-image-width, 100%);
  max-width: 100%;
  margin: 0;
  border-radius: 8px;
  overflow: visible;
}

.crm-ve-image-figure.is-selected {
  outline: none;
}

.crm-ve-image-figure.is-selected .crm-ve-image-frame {
  display: block;
}

.crm-ve-image-figure.is-selected::after {
  content: '';
  position: absolute;
  inset: -3px;
  border: 2px solid var(--crm-ve-accent);
  border-radius: 10px;
  pointer-events: none;
  z-index: 1;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.5), 0 0 0 3px rgba(37,99,235,0.15);
}

.crm-ve-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  user-select: none;
  -webkit-user-drag: none;
}

.crm-ve-image-caption {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--crm-ve-text-muted);
  padding: 4px 8px;
  margin-top: 4px;
  line-height: 1.4;
  min-height: 1.4em;
  outline: none;
}

.crm-ve-image-caption:empty::before {
  content: attr(data-placeholder);
  color: var(--crm-ve-text-muted);
  opacity: 0.5;
}

.crm-ve-readonly-image-block {
  display: flex;
  width: 100%;
  margin: 14px 0;
}

.crm-ve-readonly-image-block[data-align="left"] {
  justify-content: flex-start;
}

.crm-ve-readonly-image-block[data-align="center"] {
  justify-content: center;
}

.crm-ve-readonly-image-block[data-align="right"] {
  justify-content: flex-end;
}

.crm-ve-readonly-figure {
  width: var(--crm-ve-image-width, 100%);
  max-width: 100%;
  margin: 0;
}

.crm-ve-readonly-figure img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: 12px;
}

.crm-ve-readonly-figure figcaption {
  margin-top: 8px;
  text-align: center;
  color: var(--crm-ve-text-muted);
  font-size: 12px;
}

.crm-ve-image-frame {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.crm-ve-resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  background: var(--crm-ve-accent);
  border-radius: 4px;
  pointer-events: auto;
  z-index: 3;
  cursor: ew-resize;
  padding: 0;
  margin: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  touch-action: none;
}

.crm-ve-resize-handle:hover,
.crm-ve-resize-handle.is-active {
  transform: scale(1.15);
}

.crm-ve-resize-handle.is-active {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16), 0 2px 8px rgba(15,23,42,0.24);
}

.crm-ve-resize-left:hover,
.crm-ve-resize-left.is-active,
.crm-ve-resize-handle-left:hover,
.crm-ve-resize-handle-left.is-active,
.crm-ve-resize-right:hover,
.crm-ve-resize-right.is-active,
.crm-ve-resize-handle-right:hover,
.crm-ve-resize-handle-right.is-active {
  transform: translateY(-50%) scale(1.15);
}

.crm-ve-resize-left,
.crm-ve-resize-handle-left {
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
}

.crm-ve-resize-right,
.crm-ve-resize-handle-right {
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
}

.crm-ve-resize-bottom-left,
.crm-ve-resize-handle-bottom-left {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize;
}

.crm-ve-resize-bottom-right,
.crm-ve-resize-handle-bottom-right {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}

.crm-ve-image-toolbar {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: #ffffff !important;
  border: 1px solid var(--crm-ve-border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

.crm-ve-image-toolbar.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.crm-ve-image-toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--crm-ve-text) !important;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
  padding: 0 8px;
  line-height: 1;
  white-space: nowrap;
}

.crm-ve-image-toolbar-btn:has(svg) {
  width: 32px;
  padding: 0;
}

.crm-ve-image-toolbar-btn:hover {
  background: var(--crm-ve-accent-light);
  color: var(--crm-ve-accent) !important;
}

.crm-ve-image-toolbar-btn.is-active {
  color: var(--crm-ve-accent) !important;
  background: var(--crm-ve-accent-light);
}

.crm-ve-image-toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--crm-ve-border);
  margin: 0 4px;
  flex-shrink: 0;
}

.crm-ve-resize-badge {
  position: fixed;
  padding: 3px 10px;
  background: #ffffff !important;
  color: var(--crm-ve-text) !important;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--crm-ve-border);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.14);
  pointer-events: none;
  z-index: 1001;
  white-space: nowrap;
  display: none;
}

.crm-ve-resize-badge.is-visible {
  display: block;
}

.crm-ve-drop-indicator {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--crm-ve-accent);
  border-radius: 2px;
  z-index: 5;
  pointer-events: none;
}

.crm-ve-drop-indicator.is-visible {
  display: block;
}

.crm-ve-upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  margin: 12px 0;
  border: 2px dashed var(--crm-ve-border);
  border-radius: 12px;
  background: var(--crm-ve-surface-soft);
  text-align: center;
  gap: 8px;
}

.crm-ve-upload-placeholder-icon {
  font-size: 28px;
  color: var(--crm-ve-text-muted);
  opacity: 0.6;
}

.crm-ve-upload-placeholder-name {
  font-size: 13px;
  color: var(--crm-ve-text);
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-ve-upload-placeholder-size {
  font-size: 11px;
  color: var(--crm-ve-text-muted);
}

.crm-ve-upload-progress {
  width: 120px;
  height: 4px;
  background: var(--crm-ve-border);
  border-radius: 2px;
  overflow: hidden;
}

.crm-ve-upload-progress-bar {
  height: 100%;
  background: var(--crm-ve-accent);
  border-radius: 2px;
  transition: width 0.15s ease;
  width: 0%;
}

.crm-ve-upload-error {
  font-size: 12px;
  color: var(--crm-ve-danger);
  margin-top: 4px;
}

.crm-ve-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: #ffffff;
  color: var(--crm-ve-text);
  font-size: 13px;
  border-radius: 10px;
  border: 1px solid var(--crm-ve-border);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  max-width: 320px;
}

.crm-ve-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.crm-ve-toast.is-error {
  background: var(--crm-ve-danger);
}

.crm-ve-toast.is-success {
  background: var(--crm-ve-success);
}

.crm-ve-hidden-file-input {
  display: none !important;
}

.crm-ve-source-textarea {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
}

.crm-ve-drag-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, 0.05);
  border: 2px dashed var(--crm-ve-accent);
  border-radius: var(--crm-ve-radius);
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.crm-ve-drag-overlay.is-visible {
  opacity: 1;
}

.crm-ve-drag-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--crm-ve-accent);
  font-size: 14px;
  font-weight: 500;
}

.crm-ve-drag-overlay-content i {
  font-size: 32px;
}

.crm-ve-image-settings-popover {
  position: fixed;
  background: #ffffff !important;
  border: 1px solid var(--crm-ve-border);
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
  z-index: 1002;
  padding: 16px;
  min-width: 240px;
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

.crm-ve-image-settings-popover.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.crm-ve-image-settings-popover label {
  display: block;
  font-size: 11px;
  color: var(--crm-ve-text-muted);
  margin-bottom: 4px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.crm-ve-image-settings-popover input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--crm-ve-border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--crm-ve-text);
  font-size: 13px;
  outline: none;
  margin-bottom: 10px;
}

.crm-ve-image-settings-popover input:focus {
  border-color: var(--crm-ve-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.crm-ve-image-settings-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.crm-ve-image-settings-actions button {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease;
}

.crm-ve-image-settings-cancel {
  background: var(--crm-ve-surface-soft);
  color: var(--crm-ve-text-muted);
}

.crm-ve-image-settings-cancel:hover {
  background: var(--crm-ve-accent-light);
  color: var(--crm-ve-accent);
}

.crm-ve-image-settings-apply {
  background: var(--crm-ve-accent);
  color: #fff;
}

.crm-ve-image-settings-apply:hover {
  filter: brightness(1.1);
}

.crm-ve-link-popover {
  position: fixed;
  background: #ffffff !important;
  border: 1px solid var(--crm-ve-border);
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
  z-index: 1002;
  padding: 16px;
  min-width: 280px;
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

.crm-ve-link-popover.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.crm-ve-link-popover label {
  display: block;
  font-size: 11px;
  color: var(--crm-ve-text-muted);
  margin-bottom: 4px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.crm-ve-link-popover input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--crm-ve-border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--crm-ve-text);
  font-size: 13px;
  outline: none;
  margin-bottom: 4px;
}

.crm-ve-link-popover input:focus {
  border-color: var(--crm-ve-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.crm-ve-link-popover-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.crm-ve-link-popover-actions button {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease;
}

/* Mobile responsive */
@media (max-width: 767.98px) {
  .crm-ve-toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 1px;
    padding: 6px 4px;
  }

  .crm-ve-toolbar::-webkit-scrollbar {
    display: none;
  }

  .crm-ve-toolbar-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    font-size: 13px;
  }

  .crm-ve-image-toolbar-btn {
    width: 36px;
    height: 36px;
  }

  .crm-ve-content {
    padding: 10px 12px;
  }

  .crm-ve-image-figure,
  .crm-ve-readonly-figure {
    width: 100% !important;
  }

  .crm-ve-image-toolbar {
    position: absolute;
    left: 8px !important;
    right: 8px;
    bottom: 8px;
    top: auto !important;
    overflow-x: auto;
    max-width: none;
  }

  .crm-ve-resize-handle-left,
  .crm-ve-resize-handle-right {
    display: none;
  }

  .crm-ve-editor {
    --crm-ve-radius: 12px;
  }
}
