/* Solidity Syntax Highlighting Styles */

/* Code editor container - Fixed container positioning and overflow */
.code-editor-wrapper {
    position: relative;
    display: flex;
    background: #0d1117;
    border: 2px solid var(--primary-neon);
    border-radius: 8px;
    overflow: hidden;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    line-height: 21px;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
}

/* Editor content container */
.editor-content {
    position: relative;
    flex: 1;
    height: 100%;
    overflow: hidden;
}

/* Syntax highlighting overlay */
.syntax-highlighted {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    padding: 15px;
    margin: 0;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    line-height: 21px;
    white-space: pre;
    overflow: auto;
    z-index: 1;
    box-sizing: border-box;
    background: transparent;
    border: none;
    outline: none;
}

/* Code editor textarea - CRITICAL: Must be transparent for highlighting to show */
.code-editor-wrapper textarea {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    padding: 15px;
    margin: 0;
    background: transparent;
    border: none;
    outline: none;
    color: transparent !important; /* CRITICAL: Must be transparent */
    caret-color: #00ff41 !important; /* Visible cursor */
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    line-height: 21px;
    resize: none;
    white-space: pre;
    overflow: auto;
    tab-size: 4;
    -moz-tab-size: 4;
    box-sizing: border-box;
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
}

/* Selection styling */
.code-editor-wrapper textarea::selection {
    background: rgba(0, 255, 65, 0.3) !important;
    color: transparent !important;
}

.code-editor-wrapper textarea::-moz-selection {
    background: rgba(0, 255, 65, 0.3) !important;
    color: transparent !important;
}

/* Line numbers - Fixed positioning and overflow */
.line-numbers {
    position: relative;
    background: #161b22;
    color: #6e7681;
    padding: 15px 10px;
    border-right: 1px solid #30363d;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    line-height: 21px;
    text-align: right;
    user-select: none;
    min-width: 60px;
    width: 60px;
    overflow: hidden;
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 3;
}

.line-number {
    display: block;
    padding: 0;
    margin: 0;
    color: #6e7681;
    font-weight: normal;
    font-size: 14px;
    line-height: 21px;
    height: 21px;
    font-family: 'Fira Code', 'Courier New', monospace;
    /* Debugging: Add subtle background to visualize alignment */
    /* background: rgba(255, 0, 0, 0.1); */
}

.line-number.current {
    color: #00ff41;
    font-weight: bold;
}

/* Syntax highlighting colors - Enhanced visibility and cyberpunk theme */
.keyword {
    color: #ff0080 !important; /* Hot pink for keywords */
    font-weight: 600;
}

.type {
    color: #00d4ff !important; /* Cyan for types */
    font-weight: 500;
}

.string {
    color: #ffff00 !important; /* Bright yellow for strings */
}

.number {
    color: #00ff41 !important; /* Neon green for numbers */
}

.comment {
    color: #888888 !important; /* Gray for comments */
    font-style: italic;
}

.operator {
    color: #ff0080 !important; /* Hot pink for operators */
}

.builtin {
    color: #ffa500 !important; /* Orange for builtins */
    font-weight: 500;
}

.function {
    color: #00ff41 !important; /* Neon green for functions */
    font-weight: 500;
}

.constant {
    color: #00d4ff !important; /* Cyan for constants */
    font-weight: 600;
    text-transform: uppercase;
}

.identifier {
    color: #ffffff !important; /* White for identifiers */
}

/* Error and warning highlights */
.error-highlight {
    background: rgba(255, 0, 0, 0.2);
    border-bottom: 2px wavy #ff4444;
    position: relative;
}

.warning-highlight {
    background: rgba(255, 255, 0, 0.1);
    border-bottom: 2px wavy #ffaa00;
    position: relative;
}

.error-tooltip,
.warning-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1c2128;
    color: #f0f6fc;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    border: 1px solid #30363d;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.error-tooltip {
    border-color: #ff4444;
}

.warning-tooltip {
    border-color: #ffaa00;
}

.error-highlight:hover .error-tooltip,
.warning-highlight:hover .warning-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Bracket matching */
.bracket-match {
    background: rgba(0, 255, 65, 0.3);
    border-radius: 2px;
}

.bracket-mismatch {
    background: rgba(255, 0, 0, 0.3);
    border-radius: 2px;
}

/* Auto-completion popup */
.completion-popup {
    position: absolute;
    background: #1c2128;
    border: 1px solid #30363d;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    font-family: 'Fira Code', monospace;
    font-size: 13px;
}

.completion-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #30363d;
}

.completion-item:hover,
.completion-item.selected {
    background: #2d333b;
}

.completion-item:last-child {
    border-bottom: none;
}

.completion-icon {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    color: #fff;
}

.completion-icon.keyword {
    background: #ff7b72;
}

.completion-icon.type {
    background: #79c0ff;
}

.completion-icon.function {
    background: #d2a8ff;
}

.completion-icon.template {
    background: #ffa657;
}

.completion-text {
    flex: 1;
    color: #f0f6fc;
}

.completion-description {
    color: #8b949e;
    font-size: 11px;
    margin-left: 8px;
}

/* Enhanced scrollbar for code editor - Neon theme matching */
.code-editor-wrapper::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.code-editor-wrapper::-webkit-scrollbar-track {
    background: #161b22;
    border-radius: 6px;
}

.code-editor-wrapper::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-neon), var(--secondary-neon));
    border-radius: 6px;
    border: 2px solid #161b22;
}

.code-editor-wrapper::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--secondary-neon), var(--primary-neon));
}

.code-editor-wrapper::-webkit-scrollbar-corner {
    background: #161b22;
}

/* Additional scrollbar for textarea inside wrapper */
.code-editor-wrapper textarea::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.code-editor-wrapper textarea::-webkit-scrollbar-track {
    background: #161b22;
    border-radius: 6px;
}

.code-editor-wrapper textarea::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-neon), var(--secondary-neon));
    border-radius: 6px;
    border: 2px solid #161b22;
}

.code-editor-wrapper textarea::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--secondary-neon), var(--primary-neon));
}

.code-editor-wrapper textarea::-webkit-scrollbar-corner {
    background: #161b22;
}

/* Code folding */
.fold-marker {
    position: absolute;
    left: -20px;
    width: 16px;
    height: 16px;
    background: #30363d;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    color: #8b949e;
    user-select: none;
}

.fold-marker:hover {
    background: #484f58;
    color: #f0f6fc;
}

.fold-marker.folded::before {
    content: '+';
}

.fold-marker.expanded::before {
    content: '-';
}

/* Search and replace */
.search-replace-panel {
    position: absolute;
    top: 0;
    right: 0;
    background: #1c2128;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 10px;
    z-index: 1000;
    display: none;
}

.search-replace-panel.active {
    display: block;
}

.search-input,
.replace-input {
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 4px;
    color: #f0f6fc;
    padding: 4px 8px;
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    width: 200px;
    margin-bottom: 5px;
}

.search-input:focus,
.replace-input:focus {
    outline: none;
    border-color: var(--primary-neon);
}

.search-results {
    color: #8b949e;
    font-size: 11px;
    margin-bottom: 5px;
}

.search-match {
    background: rgba(255, 204, 0, 0.3);
    border-radius: 2px;
}

.search-match.current {
    background: rgba(255, 204, 0, 0.6);
}

/* Minimap */
.minimap {
    position: absolute;
    right: 0;
    top: 0;
    width: 100px;
    height: 100%;
    background: #161b22;
    border-left: 1px solid #30363d;
    overflow: hidden;
    opacity: 0.7;
    pointer-events: none;
}

.minimap-content {
    transform: scale(0.1);
    transform-origin: top left;
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre;
    color: #8b949e;
}

.minimap-viewport {
    position: absolute;
    background: rgba(0, 255, 65, 0.2);
    border: 1px solid var(--primary-neon);
    pointer-events: auto;
    cursor: pointer;
}

/* Animations */
@keyframes syntax-fade-in {
    from {
        opacity: 0;
        transform: translateY(2px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.syntax-highlighted span {
    animation: syntax-fade-in 0.2s ease-out;
}

/* Responsive design */
@media (max-width: 768px) {
    .code-editor-wrapper {
        font-size: 12px;
    }
    
    .line-numbers {
        font-size: 11px;
        padding: 10px 5px;
        min-width: 40px;
    }
    
    .code-editor-wrapper textarea {
        font-size: 12px;
        padding: 10px;
    }
    
    .completion-popup {
        max-height: 150px;
    }
    
    .minimap {
        width: 80px;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .keyword {
        color: #ff9999;
    }
    
    .type {
        color: #99ccff;
    }
    
    .string {
        color: #ccffcc;
    }
    
    .comment {
        color: #cccccc;
    }
    
    .operator {
        color: #ffcccc;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .syntax-highlighted span {
        animation: none;
    }
    
    .completion-item {
        transition: none;
    }
    
    .error-tooltip,
    .warning-tooltip {
        transition: none;
    }
}

/* Additional container fixes for better containment and overflow prevention */
.contract-content .code-editor {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    position: relative;
}

.contract-content .code-editor-wrapper {
    height: 100%;
    max-height: 100%;
}

/* Prevent content from spilling outside container */
.contract-panel {
    contain: layout style paint;
}

.code-editor-wrapper {
    contain: layout style paint size;
}

/* Enhanced mobile responsiveness */
@media (max-width: 768px) {
    .code-editor-wrapper {
        font-size: 12px;
        border-radius: 8px;
    }
    
    .line-numbers {
        min-width: 40px;
        padding: 10px 8px;
        font-size: 11px;
    }
    
    .code-editor-wrapper textarea {
        padding: 10px;
        font-size: 12px;
    }
}