/* ============================================================
   Strata Platform -- Block Editor Styles
   Shared component for rich block-based content editing.
   All classes prefixed with .be- (block editor).
   ============================================================ */

/* --- Editor container --- */
.be-editor {
  position: relative;
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
  outline: none;
}

.be-editor.be-readonly {
  pointer-events: auto;
}

.be-editor.be-readonly .be-drag-handle {
  display: none;
}

/* --- Block wrapper --- */
.be-block {
  position: relative;
  padding: 4px 0;
  padding-left: 28px;
  transition: background var(--transition-speed) var(--transition-fn);
}

.be-block.be-selected {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 0;
}

.be-block.be-selected.be-select-first {
  border-radius: var(--button-radius) var(--button-radius) 0 0;
}

.be-block.be-selected.be-select-last {
  border-radius: 0 0 var(--button-radius) var(--button-radius);
}

.be-block.be-selected.be-select-first.be-select-last {
  border-radius: var(--button-radius);
}

.be-block.be-drop-above::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  z-index: 2;
}

.be-block.be-drop-below::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  z-index: 2;
}

/* --- Drag handle --- */
.be-drag-handle {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  opacity: 0;
  transition: opacity var(--transition-speed) var(--transition-fn);
  color: var(--text-tertiary);
  border: none;
  background: none;
  padding: 0;
  border-radius: 4px;
  z-index: 1;
}

.be-drag-handle:hover {
  color: var(--text-secondary);
  background: var(--border);
}

.be-drag-handle:active {
  cursor: grabbing;
}

.be-block:hover .be-drag-handle,
.be-block:focus-within .be-drag-handle {
  opacity: 1;
}

.be-drag-handle svg {
  pointer-events: none;
}

/* --- Editable content area --- */
.be-content {
  outline: none;
  min-height: 1.65em;
  word-break: break-word;
  white-space: pre-wrap;
}

.be-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
  pointer-events: none;
  font-style: normal;
}

/* --- Paragraph --- */
.be-block-paragraph .be-content {
  /* default styling */
}

/* --- Headings --- */
.be-block-h1 .be-content {
  font-size: 1.75em;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.be-block-h2 .be-content {
  font-size: 1.375em;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.be-block-h3 .be-content {
  font-size: 1.125em;
  font-weight: 600;
  line-height: 1.4;
}

/* --- Bullet list --- */
.be-block-bullet {
  display: flex;
  align-items: flex-start;
}

.be-block-bullet .be-list-marker {
  flex-shrink: 0;
  width: 20px;
  height: 1.65em;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  font-size: 18px;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.be-block-bullet .be-content {
  flex: 1;
}

/* --- Numbered list --- */
.be-block-numbered {
  display: flex;
  align-items: flex-start;
}

.be-block-numbered .be-list-marker {
  flex-shrink: 0;
  min-width: 20px;
  height: 1.65em;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  color: var(--text-tertiary);
  font-size: 14px;
  font-weight: 500;
  user-select: none;
  pointer-events: none;
}

.be-block-numbered .be-content {
  flex: 1;
}

/* --- Task --- */
.be-block-task {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.be-task-checkbox {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 4px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--input-bg);
  cursor: pointer;
  transition: all var(--transition-speed) var(--transition-fn);
  position: relative;
}

.be-task-checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.be-task-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.be-block-task.be-task-done .be-content {
  text-decoration: line-through;
  color: var(--text-tertiary);
}

.be-block-task .be-content {
  flex: 1;
}

/* --- Callout --- */
.be-block-callout {
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-radius: 0 var(--button-radius) var(--button-radius) 0;
  padding: 12px 16px 12px 44px;
}

.be-block-callout .be-content {
  min-height: 1.65em;
}

/* --- Image --- */
.be-block-image {
  padding-left: 28px;
  text-align: center;
}

.be-image-wrapper {
  display: inline-block;
  max-width: 100%;
  position: relative;
}

.be-image-wrapper img {
  max-width: 100%;
  border-radius: var(--button-radius);
  display: block;
  cursor: pointer;
  transition: opacity var(--transition-speed) var(--transition-fn);
}

/* Annotation preview canvas (overlays image thumbnail) */
.be-img-ann-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  border-radius: var(--button-radius);
}

.be-image-wrapper img:hover {
  opacity: 0.92;
}

/* Annotation badge on image thumbnail */
.be-img-ann-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: rgba(255, 255, 255, 0.85);
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 1;
}

.be-img-ann-badge:hover {
  background: color-mix(in srgb, var(--accent) 70%, transparent);
  color: #fff;
}

.be-img-ann-badge svg {
  flex-shrink: 0;
}

[data-theme="light"] .be-img-ann-badge {
  background: rgba(255, 255, 255, 0.85);
  color: rgba(0, 0, 0, 0.7);
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] .be-img-ann-badge:hover {
  background: color-mix(in srgb, var(--accent) 85%, transparent);
  color: #fff;
}

/* Image resize handles (Notion-style vertical pill grips on left/right edges) */
.be-img-resize-handle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 42px;
  max-height: 40%;
  background: rgba(15, 15, 15, 0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  cursor: ew-resize;
  z-index: 2;
  touch-action: none;
}
.be-image-wrapper:hover .be-img-resize-handle,
.be-img-resizing .be-img-resize-handle {
  opacity: 1;
}
.be-img-resize-handle:hover {
  background: rgba(15, 15, 15, 0.75);
}
.be-img-resize-w { left: 6px; }
.be-img-resize-e { right: 6px; }
.be-img-resizing {
  user-select: none;
}
[data-theme="light"] .be-img-resize-handle {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(0, 0, 0, 0.35);
  box-shadow: var(--shadow-sm);
}
[data-theme="light"] .be-img-resize-handle:hover {
  background: rgba(255, 255, 255, 0.9);
}

.be-image-caption {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  outline: none;
  text-align: center;
  min-height: 1.4em;
}

.be-image-caption:empty::before {
  content: 'Add a caption...';
  color: var(--text-tertiary);
  pointer-events: none;
}

.be-image-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border: 2px dashed var(--border);
  border-radius: var(--button-radius);
  color: var(--text-tertiary);
}

.be-image-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: be-spin 0.7s linear infinite;
}

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

/* --- Divider --- */
.be-block-divider {
  padding: 16px 28px 16px;
}

.be-divider-line {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
}

/* --- Spacer --- */
.be-block-spacer {
  padding-left: 28px;
  position: relative;
}

.be-block-spacer:hover .be-spacer-inner {
  border-color: var(--text-tertiary);
}

.be-spacer-inner {
  height: 32px;
  border: 1px dashed transparent;
  border-radius: var(--button-radius);
  transition: border-color var(--transition-speed) var(--transition-fn);
}

.be-spacer-resize {
  position: absolute;
  bottom: -2px;
  left: 28px;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  opacity: 0;
  transition: opacity var(--transition-speed) var(--transition-fn);
  background: linear-gradient(transparent, color-mix(in srgb, var(--accent) 30%, transparent));
  border-radius: 0 0 var(--button-radius) var(--button-radius);
}

.be-block-spacer:hover .be-spacer-resize {
  opacity: 1;
}

/* --- Slash command menu --- */
.be-slash-menu {
  position: absolute;
  z-index: 100;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow);
  max-height: 300px;
  overflow-y: auto;
  min-width: 220px;
  padding: 6px;
}

.be-slash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--button-radius);
  cursor: pointer;
  color: var(--text-primary);
  font-size: 14px;
  transition: background var(--transition-speed) var(--transition-fn);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.be-slash-item:hover,
.be-slash-item.be-slash-active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.be-slash-item-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.be-slash-item-icon svg {
  width: 16px;
  height: 16px;
}

.be-slash-item-label {
  flex: 1;
  font-weight: 500;
}

/* Block-actions menu (host-supplied items via opts.extraBlockActions).
   Anchored to the drag handle on click. Style intentionally mirrors
   .be-slash-menu so the editor's two body-mounted popovers feel like
   one family. */
.be-block-actions-menu {
  position: fixed;
  z-index: 9000;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow);
  min-width: 240px;
  max-width: 320px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.be-block-actions-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: var(--button-radius);
  text-align: left;
  font: inherit;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  width: 100%;
  transition: background var(--transition-speed) var(--transition-fn);
}

.be-block-actions-item:hover,
.be-block-actions-item:focus-visible {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  outline: none;
}

.be-block-actions-item svg {
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
}

.be-slash-no-results {
  padding: 12px 10px;
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
}

/* --- Format bar (floating toolbar) --- */
.be-format-bar {
  position: fixed;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--button-radius);
  box-shadow: var(--shadow);
  pointer-events: auto;
  user-select: none;
}

.be-format-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition-speed) var(--transition-fn);
  padding: 0;
}

.be-format-btn:hover {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--text-primary);
}

.be-format-btn.be-format-active {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent);
}

.be-format-separator {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

/* --- Lightbox (Lumen-style layout) --- */
.be-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  animation: be-fade-in 0.2s ease;
}

.be-lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
}

.be-lb-content {
  position: absolute;
  inset: 60px 70px 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.be-lb-canvas-wrap {
  position: relative;
  transition: transform 0.15s ease;
  transform-origin: center center;
}

.be-lb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
}

.be-lb-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  z-index: 2;
}

.be-lb-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.be-lb-actions {
  position: absolute;
  top: 14px;
  left: 16px;
  display: flex;
  gap: 6px;
  z-index: 2;
}

.be-lb-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.8);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s ease;
}

.be-lb-action-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.be-lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  z-index: 2;
}

.be-lb-prev { left: 14px; }
.be-lb-next { right: 14px; }

.be-lb-nav:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.be-lb-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.5);
  font-size: 13px;
  z-index: 2;
}

.be-lb-counter span {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
}

.be-lb-caption {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  max-width: 400px;
  text-align: center;
  z-index: 2;
}

.be-lb-zoom-bar {
  position: absolute;
  bottom: 14px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 8px;
  border-radius: 16px;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.be-lb-zoom-bar.be-lb-zoom-visible {
  opacity: 1;
  pointer-events: auto;
}

.be-lb-zoom-btn {
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.8);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.be-lb-zoom-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.be-lb-zoom-label {
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  min-width: 36px;
  text-align: center;
}

@keyframes be-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Search highlights --- */
.be-search-highlight {
  background: color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: 2px;
  padding: 0 1px;
}

.be-search-highlight-active {
  background: color-mix(in srgb, var(--warning) 70%, transparent);
  outline: 2px solid var(--warning);
  outline-offset: 1px;
}

/* --- Inline formatting inside contentEditable --- */
.be-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.be-content a:hover {
  opacity: 0.85;
  cursor: pointer;
}

.be-content a::after {
  content: ' \2197';
  font-size: 0.7em;
  opacity: 0;
  transition: opacity 0.15s;
}

.be-content a:hover::after {
  opacity: 0.6;
}

.be-content code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.88em;
  background: color-mix(in srgb, var(--accent) 10%, var(--input-bg));
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-primary);
}

/* --- Scrollbar for slash menu --- */
.be-slash-menu::-webkit-scrollbar {
  width: 6px;
}

.be-slash-menu::-webkit-scrollbar-track {
  background: transparent;
}

.be-slash-menu::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* --- Drag ghost (while dragging) --- */
.be-drag-ghost {
  opacity: 0.4;
}

/* --- Read-only tweaks --- */
.be-readonly .be-content {
  cursor: default;
}

.be-readonly .be-task-checkbox {
  pointer-events: none;
}

/* --- Lightbox annotation canvas overlay --- */
.be-lb-ann-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .be-image-spinner {
    animation: none;
  }
  .be-lightbox {
    animation: none;
  }
}
