﻿/**
 * CodeMirror Editor Styles for Page Builder
 * Used with the CodeMirrorEditor.razor component
 */

/* ========== FULLSCREEN WRAPPER ========== */
/* Full-screen mode wrapper - covers entire screen */
.codemirror-editor-wrapper.fullscreen-wrapper {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: var(--bs-body-bg);
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.codemirror-editor-wrapper.fullscreen-wrapper .codemirror-toolbar {
    flex-shrink: 0;
    background: var(--bs-body-bg);
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--bs-border-color);
    margin-bottom: 0 !important;
    padding: 0.75rem 1rem;
}

.codemirror-editor-wrapper.fullscreen-wrapper .codemirror-container {
    flex: 1;
    border-radius: 0 !important;
    border: none !important;
    border-top: none !important;
}

.codemirror-editor-wrapper.fullscreen-wrapper .codemirror-container .CodeMirror {
    height: 100% !important;
}

/* Fullscreen exit button highlight */
.codemirror-editor-wrapper.fullscreen-wrapper .btn-warning {
    animation: pulse-warning 2s infinite;
}

@keyframes pulse-warning {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255, 193, 7, 0); }
}

/* Editor wrapper */
.codemirror-editor-wrapper {
    position: relative;
}

/* Toolbar */
.codemirror-toolbar {
    padding: 0.5rem;
    background-color: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    border-bottom: none;
    border-radius: 0.375rem 0.375rem 0 0;
}

.codemirror-toolbar + .codemirror-container {
    border-radius: 0 0 0.375rem 0.375rem !important;
}

/* Container */
.codemirror-container {
    overflow: hidden;
}

.codemirror-container .CodeMirror {
    height: 100%;
    font-family: 'Consolas', 'Monaco', 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* ========== CURSOR FIX ========== */
/* Ensure cursor is visible in all themes */
.CodeMirror-cursor {
    border-left: 2px solid #528bff !important;
    border-right: none !important;
    width: 0 !important;
    visibility: visible !important;
}

/* Cursor color for dark themes */
.cm-s-monokai .CodeMirror-cursor,
.cm-s-dracula .CodeMirror-cursor,
.cm-s-material .CodeMirror-cursor {
    border-left-color: #f8f8f0 !important;
}

/* Cursor color for light themes */
.cm-s-eclipse .CodeMirror-cursor,
.cm-s-default .CodeMirror-cursor {
    border-left-color: #000 !important;
}

/* Blinking cursor animation */
@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0; }
    100% { opacity: 1; }
}

.CodeMirror-focused .CodeMirror-cursor {
    animation: blink 1.2s step-end infinite;
}

/* Secondary cursor for multi-cursor editing */
.CodeMirror-cursor.CodeMirror-secondarycursor {
    border-left-color: #c0c0c0 !important;
}

/* ========== END CURSOR FIX ========== */

/* Gutter styling */
.CodeMirror-gutters {
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.CodeMirror-linenumber {
    padding: 0 8px 0 5px;
    min-width: 20px;
    color: rgba(255, 255, 255, 0.4);
}

/* Fold gutter */
.CodeMirror-foldmarker {
    color: #0d6efd;
    text-shadow: none;
    font-family: inherit;
    line-height: inherit;
    cursor: pointer;
}

/* Selection */
.CodeMirror-selected {
    background: rgba(13, 110, 253, 0.3) !important;
}

.CodeMirror-focused .CodeMirror-selected {
    background: rgba(13, 110, 253, 0.4) !important;
}

/* Matching brackets */
.CodeMirror-matchingbracket {
    color: #0d6efd !important;
    background: rgba(13, 110, 253, 0.2);
    font-weight: bold;
}

/* Scroll bars */
.CodeMirror-vscrollbar,
.CodeMirror-hscrollbar {
    outline: none;
}

.CodeMirror-scrollbar-filler {
    background: transparent;
}

/* Placeholder */
.CodeMirror-placeholder {
    color: rgba(255, 255, 255, 0.3);
    font-style: italic;
}

/* Active line */
.CodeMirror-activeline-background {
    background: rgba(255, 255, 255, 0.05);
}

/* Hints/autocomplete */
.CodeMirror-hints {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
    max-height: 200px;
    overflow-y: auto;
    z-index: 10000;
}

.CodeMirror-hint {
    padding: 4px 8px;
    color: var(--bs-body-color);
}

.CodeMirror-hint-active {
    background: var(--bs-primary);
    color: white;
}

/* Theme adjustments for light mode */
[data-bs-theme="light"] .codemirror-toolbar {
    background-color: #f8f9fa;
}

[data-bs-theme="light"] .CodeMirror-linenumber {
    color: #6c757d;
}

[data-bs-theme="light"] .CodeMirror-placeholder {
    color: rgba(0, 0, 0, 0.4);
}

[data-bs-theme="light"] .CodeMirror-gutters {
    border-right-color: #ddd;
}

/* Eclipse theme adjustments for light mode */
[data-bs-theme="light"] .cm-s-eclipse .CodeMirror-gutters {
    border-right: 1px solid #ddd;
}

/* ========== MINI EDITOR STYLES ========== */
/* For smaller inline editors (e.g., in config forms) */
.CodeMirror {
    height: 100%;
    font-family: 'Consolas', monospace;
    font-size: 14px;
}
.codemirror-mini .CodeMirror {
    font-size: 12px;
    line-height: 1.4;
}

.codemirror-mini .codemirror-toolbar {
    padding: 0.25rem 0.5rem;
}

.codemirror-mini .codemirror-toolbar .badge {
    font-size: 0.65rem;
}
