/* ==========================================================================
   Universal Visual Edit Core Styles & Floating Inspector
   Shared across Life OS, Grid Meal, Grid Vault, and future apps.
   ========================================================================== */

/* Host sidebar toolbar buttons */
.visual-edit-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.btn-visual-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--bg-card-elevated, #ffffff);
  border: 1px solid var(--border-subtle, #e2e8f0);
  color: var(--text-primary, #1e293b);
  padding: 7px 9px;
  border-radius: var(--radius-sm, 6px);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  min-height: 36px;
  box-sizing: border-box;
}

.btn-visual-edit:hover {
  background: #ffffff;
  border-color: var(--border-highlight, #94a3b8);
  transform: translateY(-1px);
}

.btn-visual-edit.active {
  background: linear-gradient(135deg, rgba(108, 122, 224, 0.18), rgba(168, 85, 247, 0.16));
  border-color: #6366f1;
  color: #4338ca;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.28);
  font-weight: 700;
}

.btn-visual-edit.hidden {
  display: none !important;
}

.visual-edit-actions {
  display: flex;
  gap: 6px;
  width: 100%;
  animation: veSlideDown 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.visual-edit-actions.hidden {
  display: none !important;
}

@keyframes veSlideDown {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.btn-save-edit,
.btn-cancel-edit,
.btn-undo-edit {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
  box-sizing: border-box;
}

.btn-save-edit {
  background: #10b981;
  color: #ffffff;
  border-color: #059669;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.3);
}

.btn-save-edit:hover {
  background: #059669;
  transform: translateY(-1px);
}

.btn-cancel-edit {
  background: #f1f5f9;
  color: #64748b;
  border-color: #cbd5e1;
}

.btn-cancel-edit:hover {
  background: #e2e8f0;
  color: #334155;
}

.btn-undo-edit {
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
  padding: 5px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  box-sizing: border-box;
}

.btn-undo-edit:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
}

.btn-undo-edit.hidden {
  display: none !important;
}

/* When Visual Edit Mode is active, allow direct text cursor & inline editing */
body.visual-edit-mode-active {
  user-select: text;
}

body.visual-edit-mode-active *:not(#visual-edit-popover):not(#visual-edit-popover *):not(.visual-edit-bar):not(.visual-edit-bar *):not(.ve-floating-x):not(#visual-edit-delete-btn) {
  cursor: text !important;
}

.ve-inline-editing {
  outline: 2px solid #10b981 !important;
  outline-offset: 2px;
  background: rgba(16, 185, 129, 0.1) !important;
  border-radius: 4px;
  min-width: 12px;
}

.ve-delete-preview-target {
  outline: 2px dashed #ef4444 !important;
  outline-offset: 2px;
  background-color: rgba(239, 68, 68, 0.08) !important;
}

/* Floating Upper-Left 'X' Delete Layer across elements */
.visual-edit-delete-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9997;
}

.visual-edit-delete-layer.hidden {
  display: none !important;
}

.ve-floating-x {
  position: fixed;
  pointer-events: auto;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.88);
  color: #ffffff;
  border: 1.5px solid #ffffff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer !important;
  box-shadow: 0 2px 5px rgba(239, 68, 68, 0.35);
  padding: 0;
  transition: transform 0.12s ease, background 0.12s ease;
  z-index: 9997;
}

.ve-floating-x:hover {
  background: #dc2626;
  transform: scale(1.22);
  z-index: 10002;
}

/* Floating Dashed Outline Inspector Box with Upper-Left 'X' Delete Button & Transform Handles */
.visual-edit-highlight {
  position: fixed;
  pointer-events: none;
  z-index: 9998;
  border: 2px dashed #6366f1;
  background: rgba(99, 102, 241, 0.06);
  border-radius: 6px;
  box-sizing: border-box;
  transition: top 0.03s ease-out, left 0.03s ease-out, width 0.03s ease-out, height 0.03s ease-out;
}

.visual-edit-highlight.ve-selected {
  border: 2px solid #4f46e5;
  background: rgba(99, 102, 241, 0.08);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), 0 4px 18px rgba(79, 70, 229, 0.3);
}

.visual-edit-highlight.hidden {
  display: none !important;
}

/* Top toolbar floating above selected element */
.ve-transform-toolbar {
  position: absolute;
  top: -36px;
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #1e1b4b;
  color: #ffffff;
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.45);
  pointer-events: auto;
  user-select: none;
  white-space: nowrap;
  z-index: 10001;
}

.visual-edit-highlight:not(.ve-selected) .ve-tool-actions,
.visual-edit-highlight:not(.ve-selected) .ve-handle,
.visual-edit-highlight:not(.ve-selected) .ve-edge {
  display: none !important;
}

.visual-edit-highlight.ve-resizing {
  transition: none !important;
}

/* Drag to Move Grabber Bar */
.ve-drag-handle {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  color: #e0e7ff;
  font-weight: 700;
  font-size: 11px;
  cursor: grab !important;
  user-select: none;
  touch-action: none;
}

.ve-drag-handle:hover {
  background: #6366f1;
  color: #ffffff;
}

.ve-drag-handle:active {
  cursor: grabbing !important;
  background: #4f46e5;
}

.ve-tool-actions {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.ve-tool-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #e0e7ff;
  border: none;
  border-radius: 3px;
  padding: 2px 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer !important;
  line-height: 1.2;
}

.ve-tool-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.ve-size-badge {
  font-size: 10px;
  color: #c7d2fe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  padding: 0 4px;
}

.visual-edit-tag-badge {
  font-size: 10px;
  color: #a5b4fc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  padding: 0 4px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visual-edit-delete-btn {
  background: #ef4444;
  color: #ffffff;
  border: none;
  border-radius: 3px;
  width: 18px;
  height: 18px;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer !important;
  padding: 0;
  margin-left: 2px;
}

.visual-edit-delete-btn:hover {
  background: #dc2626;
}

/* 4 Draggable Edges */
.ve-edge {
  position: absolute;
  pointer-events: auto;
  z-index: 10000;
  touch-action: none;
}

.ve-edge-top {
  top: -4px;
  left: 6px;
  right: 6px;
  height: 8px;
  cursor: ns-resize;
}

.ve-edge-bottom {
  bottom: -4px;
  left: 6px;
  right: 6px;
  height: 8px;
  cursor: ns-resize;
}

.ve-edge-left {
  left: -4px;
  top: 6px;
  bottom: 6px;
  width: 8px;
  cursor: ew-resize;
}

.ve-edge-right {
  right: -4px;
  top: 6px;
  bottom: 6px;
  width: 8px;
  cursor: ew-resize;
}

.ve-edge:hover,
.ve-edge.ve-edge-active {
  background: rgba(99, 102, 241, 0.35);
}

/* 8 Resize Handles */
.ve-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1.5px solid #4f46e5;
  border-radius: 2px;
  pointer-events: auto;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
  z-index: 10001;
  touch-action: none;
}

.ve-handle:hover {
  background: #4f46e5;
  transform: scale(1.3);
}

.ve-handle-nw,
.ve-handle-ne,
.ve-handle-se,
.ve-handle-sw {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.ve-handle-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.ve-handle-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.ve-handle-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.ve-handle-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }

.ve-handle-n,
.ve-handle-s {
  left: calc(50% - 10px);
  width: 20px;
  height: 6px;
  cursor: ns-resize;
}
.ve-handle-n { top: -3px; }
.ve-handle-s { bottom: -3px; }

.ve-handle-e,
.ve-handle-w {
  top: calc(50% - 10px);
  width: 6px;
  height: 20px;
  cursor: ew-resize;
}
.ve-handle-e { right: -3px; }
.ve-handle-w { left: -3px; }

/* Drag and Drop Drop-Indicator Line */
.ve-drop-indicator {
  position: fixed;
  height: 3px;
  background: #4f46e5;
  box-shadow: 0 0 8px rgba(79, 70, 229, 0.7);
  border-radius: 2px;
  pointer-events: none;
  z-index: 10003;
  transition: top 0.05s ease-out, left 0.05s ease-out, width 0.05s ease-out;
}

.ve-drop-indicator.hidden {
  display: none !important;
}

.ve-drop-indicator.ve-drop-indicator-box {
  border: 2px dashed #4f46e5;
  background: rgba(99, 102, 241, 0.12);
  height: auto !important;
}

.ve-element-dragging {
  opacity: 0.35 !important;
  outline: 2px dashed #6366f1 !important;
}

.ve-drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 10004;
  opacity: 0.85;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  transform: rotate(2deg) scale(0.98);
}

/* Floating Toast inside Iframe / Host */
.ve-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e1b4b;
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  z-index: 10005;
  animation: veSlideDown 0.15s ease-out;
}
