/* code-editor.css */
/* Styling for the CodeMirror editor integration with Neo design system */

#code-editor-container {
  position: relative;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* CodeMirror main container */
#code-editor-container .CodeMirror {
  height: 100%;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.4;
  border: none;
  border-radius: 4px;
}

/* Ensure consistent font rendering inside the editor */
#code-editor-container .CodeMirror pre {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

/* Line numbers styling */
#code-editor-container .CodeMirror-linenumbers {
  background-color: #f8f9fa;
  border-right: 1px solid #e9ecef;
  color: #6c757d;
  padding: 0 8px;
  width: 40px !important;
}

/* Active line highlighting */
#code-editor-container .CodeMirror-activeline-background {
  background-color: rgba(0, 123, 255, 0.05);
}

/* Cursor styling */
#code-editor-container .CodeMirror-cursor {
  border-left: 2px solid #007bff;
}

/* Selection styling */
#code-editor-container .CodeMirror-selected {
  background-color: rgba(0, 123, 255, 0.15);
}

/* Gutter styling */
#code-editor-container .CodeMirror-gutters {
  background-color: #f8f9fa;
  border-right: 1px solid #e9ecef;
}

/* Fold gutter styling */
#code-editor-container .CodeMirror-foldgutter {
  width: 16px;
}

#code-editor-container .CodeMirror-foldgutter-open,
#code-editor-container .CodeMirror-foldgutter-folded {
  cursor: pointer;
  color: #6c757d;
}

#code-editor-container .CodeMirror-foldgutter-open:after {
  content: "▼";
  font-size: 10px;
}

#code-editor-container .CodeMirror-foldgutter-folded:after {
  content: "▶";
  font-size: 10px;
}

/* Syntax highlighting improvements */
#code-editor-container .cm-tag {
  color: #d73a49;
  font-weight: 600;
}

#code-editor-container .cm-attribute {
  color: #6f42c1;
}

#code-editor-container .cm-string {
  color: #032f62;
}

#code-editor-container .cm-comment {
  color: #6a737d;
  font-style: italic;
}

#code-editor-container .cm-keyword {
  color: #d73a49;
  font-weight: 600;
}

#code-editor-container .cm-number {
  color: #005cc5;
}

#code-editor-container .cm-variable {
  color: #e36209;
}

/* Matching brackets */
#code-editor-container .CodeMirror-matchingbracket {
  background-color: rgba(0, 255, 0, 0.3);
  color: inherit !important;
}

#code-editor-container .CodeMirror-nonmatchingbracket {
  background-color: rgba(255, 0, 0, 0.3);
  color: inherit !important;
}

/* Scrollbar styling for better integration */
#code-editor-container .CodeMirror-scrollbar-filler {
  background-color: #f8f9fa;
}

#code-editor-container .CodeMirror-vscrollbar,
#code-editor-container .CodeMirror-hscrollbar {
  outline: none;
}

/* Focus styling */
#code-editor-container .CodeMirror-focused {
  outline: 2px solid rgba(0, 123, 255, 0.25);
  outline-offset: -2px;
}

/* Error highlighting (can be used for validation) */
#code-editor-container .cm-error {
  color: #dc3545;
  background-color: rgba(220, 53, 69, 0.1);
  text-decoration: underline wavy #dc3545;
}

/* Search highlighting */
#code-editor-container .CodeMirror-searching {
  background-color: #ffeaa7;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  #code-editor-container .CodeMirror {
    font-size: 12px;
  }
  
  #code-editor-container .CodeMirror-linenumbers {
    width: 35px !important;
    padding: 0 6px;
  }
}

/* Dark mode support (if needed in the future) */
@media (prefers-color-scheme: dark) {
  #code-editor-container.dark-mode .CodeMirror {
    background-color: #1e1e1e;
    color: #d4d4d4;
  }
  
  #code-editor-container.dark-mode .CodeMirror-linenumbers {
    background-color: #252526;
    border-right-color: #3c3c3c;
    color: #858585;
  }
  
  #code-editor-container.dark-mode .CodeMirror-gutters {
    background-color: #252526;
    border-right-color: #3c3c3c;
  }
  
  #code-editor-container.dark-mode .CodeMirror-activeline-background {
    background-color: rgba(255, 255, 255, 0.05);
  }
  
  #code-editor-container.dark-mode .CodeMirror-selected {
    background-color: rgba(255, 255, 255, 0.15);
  }
}

/* Animation for smooth transitions */
#code-editor-container,
#website-preview-iframe {
  transition: opacity 0.2s ease-in-out;
}

/* Loading state styling */
#code-editor-container.loading {
  opacity: 0.7;
  pointer-events: none;
}

#code-editor-container.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #007bff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  transform: translate(-50%, -50%);
}

@keyframes spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Loading state for code editor when waiting for proxied content */
.code-editor-loading {
  position: absolute !important;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(248, 249, 250, 0.95);
  border: 1px solid #e9ecef;
  border-radius: 4px;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.code-editor-loading-content {
  text-align: center;
  color: #6c757d;
  font-family: system-ui, -apple-system, sans-serif;
}

.code-editor-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e9ecef;
  border-top: 3px solid #007bff;
  border-radius: 50%;
  animation: code-editor-spin 1s linear infinite;
  margin: 0 auto 12px;
}

.code-editor-loading-text {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.code-editor-loading-subtext {
  font-size: 12px;
  opacity: 0.7;
}

@keyframes code-editor-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
