/* ==========================================================================
   Visual Edit Mode Styles & Floating Inspector
   ========================================================================== */

.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);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  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);
  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;
  align-items: center;
  gap: 6px;
  width: 100%;
}

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

.btn-save-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(5, 150, 105, 0.22));
  border: 1px solid rgba(16, 185, 129, 0.45);
  color: #065f46;
  padding: 7px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  min-height: 36px;
  box-sizing: border-box;
}

.btn-save-edit:hover {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.26), rgba(5, 150, 105, 0.32));
  border-color: #10b981;
  transform: translateY(-1px);
}

.btn-cancel-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  background: var(--bg-card-elevated, #ffffff);
  border: 1px solid var(--border-subtle, #e2e8f0);
  color: var(--text-secondary, #64748b);
  padding: 7px 6px;
  border-radius: var(--radius-sm);
  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-cancel-edit:hover {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--accent-rose, #ef4444);
  transform: translateY(-1px);
}

.btn-undo-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--accent-rose);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 36px;
  box-sizing: border-box;
}

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

.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.85);
  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 */
.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.04s ease-out, left 0.04s ease-out, width 0.04s ease-out, height 0.04s ease-out;
}

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

.visual-edit-delete-btn {
  position: absolute;
  top: -11px;
  left: -11px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ef4444;
  color: #ffffff;
  border: 2px solid #ffffff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer !important;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
  padding: 0;
  z-index: 10001;
  transition: transform 0.12s ease, background 0.12s ease;
}

.visual-edit-delete-btn:hover {
  background: #dc2626;
  transform: scale(1.18);
}

.visual-edit-tag-badge {
  position: absolute;
  top: -24px;
  left: 14px;
  background: #4f46e5;
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px 4px 0 0;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Floating UI Edit Popover */
.visual-edit-popover {
  position: fixed;
  z-index: 10005;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--bg-card);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 36px rgba(15, 20, 28, 0.22), 0 2px 10px rgba(0, 0, 0, 0.08);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: opacity 0.16s ease, transform 0.16s ease;
  box-sizing: border-box;
}

.visual-edit-popover.hidden {
  display: none !important;
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
}

.ve-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ve-popover-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-primary);
}

.ve-popover-title .ve-icon {
  font-size: 1rem;
}

.ve-btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.ve-btn-close:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.06);
}

.ve-target-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 5px 8px;
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.ve-target-tag {
  color: var(--accent-indigo);
  font-weight: 700;
}

.ve-target-selector {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.ve-popover-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ve-textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-input);
  border: 1px solid var(--border-highlight);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-primary);
  resize: vertical;
  min-height: 64px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ve-textarea:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 2px rgba(108, 122, 224, 0.2);
}

.ve-chips-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ve-chips-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
}

.ve-chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ve-chip {
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.69rem;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.ve-chip:hover {
  background: var(--accent-indigo-soft);
  border-color: var(--accent-indigo);
  color: var(--accent-indigo);
}

.ve-status-message {
  font-size: 0.73rem;
  padding: 6px 9px;
  border-radius: 6px;
  line-height: 1.35;
}

.ve-status-message.error {
  background: var(--accent-rose-soft);
  color: var(--accent-rose);
  border: 1px solid rgba(224, 93, 111, 0.3);
}

.ve-status-message.success {
  background: var(--accent-emerald-soft);
  color: var(--accent-emerald);
  border: 1px solid rgba(47, 158, 119, 0.3);
}

.ve-popover-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.ve-btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 0.77rem;
  cursor: pointer;
  font-weight: 600;
}

.ve-btn-secondary:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-primary);
}

.ve-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-indigo);
  border: none;
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.12s ease;
}

.ve-btn-primary:hover:not(:disabled) {
  opacity: 0.92;
  transform: translateY(-1px);
}

.ve-btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.ve-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: ve-spin 0.6s linear infinite;
}

.ve-spinner.hidden {
  display: none;
}

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

@media (max-width: 600px) {
  .visual-edit-popover {
    width: min(340px, calc(100vw - 20px));
    left: 10px !important;
    right: 10px !important;
    margin: 0 auto;
  }
}


/* MODAL STYLES */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 35, 45, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  animation: modal-pop 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card-elevated);
}

.modal-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
}

.modal-close-btn:hover {
  background: var(--border-subtle);
  color: var(--text-primary);
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-field label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.modal-field input[type="text"],
.modal-field input[type="number"],
.modal-field select {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  height: 38px;
  box-sizing: border-box;
}

.modal-field input:focus,
.modal-field select:focus {
  outline: none;
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 2px var(--accent-indigo-soft);
}

.modal-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

@media (max-width: 640px) {
  .modal-backdrop {
    padding: 8px;
  }
  .modal-card {
    max-width: calc(100vw - 16px) !important;
    width: 100% !important;
    margin: 0 auto;
    box-sizing: border-box;
  }
  .modal-body {
    padding: 12px 14px;
    gap: 10px;
    box-sizing: border-box;
    max-width: 100%;
  }
  .modal-header {
    padding: 10px 14px;
  }
  .modal-row-2,
  .modal-row-3 {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }
  .modal-datetime-combo {
    width: 100%;
    display: flex;
    gap: 6px;
    align-items: center;
    box-sizing: border-box;
  }
  .modal-datetime-combo .modal-date-input {
    flex: 1 1 auto;
    min-width: 0;
    box-sizing: border-box;
  }
  .modal-datetime-combo .modal-time-input {
    flex: 0 0 76px;
    width: 76px;
    box-sizing: border-box;
  }
  .modal-footer {
    flex-wrap: wrap;
    gap: 8px;
  }
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

