/* Code Editor Styles Enhanced */
.code-editor-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin: 2rem 0;
}

.code-editor-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-title {
    font-weight: 600;
    color: #333;
    margin: 0;
    font-size: 1.125rem;
}

.code-language-badge {
    background: #6c757d;
    color: white;
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.code-language-badge.html {
    background: #e34f26;
}

.code-language-badge.css {
    background: #1572b6;
}

.code-language-badge.javascript {
    background: #f7df1e;
    color: #333;
}

.code-language-badge.python {
    background: #3776ab;
}

.code-language-badge.php {
    background: #777bb4;
}

.code-language-badge.sql {
    background: #336791;
}

.code-display {
    position: relative;
    direction: ltr; /* Force LTR for code */
}

.code-display-header {
    background: #2d3748;
    color: #a0aec0;
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 500;
}

.copy-button {
    background: #4a5568;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.3s ease;
    min-height: 36px;
}

.copy-button:hover {
    background: #2d3748;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.copy-button.copied {
    background: #38a169;
}

.copy-button.bg-green-600 {
    background: #38a169;
}

.copy-button.bg-green-600:hover {
    background: #2f855a;
}

/* ENHANCED CODE BLOCK */
.code-block {
    position: relative;
    background: #1a202c;
    color: #e2e8f0;
    font-family: 'JetBrains Mono', 'Monaco', 'Consolas', 'Courier New', monospace;
    overflow-x: auto;
    direction: ltr !important;
    text-align: left !important;
}

.code-block pre {
    margin: 0;
    padding: 1.25rem;
    overflow-x: auto;
    white-space: pre;
    tab-size: 4;
    -moz-tab-size: 4;
    -webkit-tab-size: 4;
    line-height: 1.6;
    font-size: 0.9375rem;
}

.code-block code {
    background: none;
    color: inherit;
    padding: 0;
    border: none;
    font-family: inherit;
    direction: ltr !important;
    unicode-bidi: embed;
}

/* PRESERVE INDENTATION */
.code-block pre,
.code-block code {
    white-space: pre !important;
    word-wrap: normal !important;
    word-break: normal !important;
}

/* Try it Yourself Section */
.try-section {
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
}

.try-header {
    padding: 1rem 1.25rem;
    background: #e9ecef;
    border-bottom: 1px solid #dee2e6;
}

.try-header h4 {
    margin: 0;
    color: #495057;
    font-size: 1rem;
    font-weight: 600;
}

.try-content {
    padding: 1.5rem;
}

.editor-output-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .editor-output-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .code-display-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .copy-button {
        width: 100%;
        min-height: 44px;
        font-size: 0.875rem;
    }
    
    .code-block pre {
        font-size: 0.8125rem;
        padding: 1rem;
        line-height: 1.5;
    }
    
    .code-editor-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}

.editor-container {
    position: relative;
}

.editor-label {
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.code-editor-wrapper {
    position: relative;
    border: 1px solid #ced4da;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.line-numbers {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: #f8f9fa;
    border-right: 1px solid #e9ecef;
    padding: 0.75rem 0.5rem;
    font-family: 'JetBrains Mono', 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: #6c757d;
    text-align: right;
    overflow: hidden;
    user-select: none;
    direction: ltr;
}

.code-editor {
    width: 100%;
    min-height: 150px;
    padding: 0.75rem 0.75rem 0.75rem 3.25rem;
    border: none;
    font-family: 'JetBrains Mono', 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    background: transparent;
    color: #333;
    direction: ltr;
    tab-size: 4;
    -moz-tab-size: 4;
    -webkit-tab-size: 4;
}

.code-editor:focus {
    box-shadow: none;
}

.output-container {
    border: 1px solid #ced4da;
    border-radius: 8px;
    min-height: 150px;
    overflow: auto;
    background: #fff;
}

.output-header {
    background: #f8f9fa;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.75rem;
    color: #6c757d;
    font-weight: 600;
}

.output-content {
    padding: 0.75rem;
    min-height: 120px;
}

.placeholder-text {
    color: #6c757d;
    font-style: italic;
    margin: 0;
    text-align: center;
    padding: 2.5rem 1.25rem;
}

.loading-spinner {
    text-align: center;
    padding: 2.5rem 1.25rem;
    color: #6c757d;
}

.loading-spinner::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #e9ecef;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.5rem;
    vertical-align: middle;
}

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

.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid #f5c6cb;
    margin: 0;
    font-size: 0.875rem;
}

/* Control Buttons */
.code-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.control-button {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 36px;
}

.control-button:hover {
    background: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.control-button.secondary {
    background: #6c757d;
}

.control-button.secondary:hover {
    background: #545b62;
}

.control-button.success {
    background: #28a745;
}

.control-button.success:hover {
    background: #1e7e34;
}

.control-button:disabled {
    background: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Responsive Design */
@media (max-width: 576px) {
    .code-controls {
        width: 100%;
        justify-content: stretch;
    }
    
    .control-button {
        flex: 1;
        justify-content: center;
        min-width: 0;
        min-height: 44px;
    }
    
    .line-numbers {
        width: 30px;
        font-size: 0.75rem;
    }
    
    .code-editor {
        padding-left: 2.5rem;
        font-size: 0.75rem;
    }
}

/* Enhanced Syntax Highlighting */
.code-block pre[class*="language-"] {
    margin: 0;
    padding: 1.25rem;
    background: #1a202c;
    border-radius: 0;
}

/* Improved token colors */
.code-block .token.comment,
.code-block .token.prolog,
.code-block .token.doctype,
.code-block .token.cdata {
    color: #a0aec0;
    font-style: italic;
}

.code-block .token.punctuation {
    color: #e2e8f0;
}

.code-block .token.property,
.code-block .token.tag,
.code-block .token.constant,
.code-block .token.symbol,
.code-block .token.deleted {
    color: #fc8181;
}

.code-block .token.boolean,
.code-block .token.number {
    color: #f6ad55;
}

.code-block .token.selector,
.code-block .token.attr-name,
.code-block .token.string,
.code-block .token.char,
.code-block .token.builtin,
.code-block .token.inserted {
    color: #68d391;
}

.code-block .token.operator,
.code-block .token.entity,
.code-block .token.url,
.language-css .token.string,
.style .token.string,
.code-block .token.variable {
    color: #81e6d9;
}

.code-block .token.atrule,
.code-block .token.attr-value,
.code-block .token.function,
.code-block .token.class-name {
    color: #fbb6ce;
}

.code-block .token.keyword {
    color: #63b3ed;
    font-weight: 600;
}

.code-block .token.regex,
.code-block .token.important {
    color: #f6ad55;
}

.code-block .token.important,
.code-block .token.bold {
    font-weight: bold;
}

.code-block .token.italic {
    font-style: italic;
}

.code-block .token.entity {
    cursor: help;
}

/* RTL ADJUSTMENTS FOR CODE */
.rtl .code-editor-container {
    direction: ltr !important;
}

.rtl .code-display,
.rtl .code-block,
.rtl .code-block pre,
.rtl .code-block code {
    direction: ltr !important;
    text-align: left !important;
}

.rtl .line-numbers {
    right: 0;
    left: auto;
    border-right: none;
    border-left: 1px solid #e9ecef;
    text-align: left;
}

.rtl .code-editor {
    padding-right: 3.25rem;
    padding-left: 0.75rem;
}

/* HIGH CONTRAST MODE */
@media (prefers-contrast: high) {
    .code-editor-container {
        border: 2px solid #000;
    }
    
    .code-block {
        border: 1px solid #fff;
    }
    
    .copy-button {
        border: 1px solid #fff;
    }
}

/* DARK MODE FOR CODE EDITOR */
.dark .code-editor-container {
    background: #1f2937;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.dark .code-editor-header {
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
    border-bottom-color: #4b5563;
}

.dark .code-title {
    color: #f9fafb;
}

.dark .code-display-header {
    background: #1f2937;
    color: #d1d5db;
}

.dark .copy-button {
    background: #6b7280;
    color: #f9fafb;
}

.dark .copy-button:hover {
    background: #4b5563;
}

.dark .copy-button.copied,
.dark .copy-button.bg-green-600 {
    background: #059669;
}

.dark .copy-button.bg-green-600:hover {
    background: #047857;
}

.dark .code-block {
    background: #111827;
    color: #f3f4f6;
}

.dark .try-section {
    border-top-color: #4b5563;
    background: #1f2937;
}

.dark .try-header {
    background: #374151;
    border-bottom-color: #4b5563;
}

.dark .try-header h4 {
    color: #f9fafb;
}

.dark .editor-label {
    color: #d1d5db;
}

.dark .code-editor-wrapper {
    border-color: #4b5563;
    background: #1f2937;
}

.dark .line-numbers {
    background: #374151;
    border-right-color: #4b5563;
    color: #9ca3af;
}

.dark .code-editor {
    background: transparent;
    color: #f9fafb;
}

.dark .output-container {
    border-color: #4b5563;
    background: #1f2937;
}

.dark .output-header {
    background: #374151;
    border-bottom-color: #4b5563;
    color: #9ca3af;
}

.dark .placeholder-text {
    color: #9ca3af;
}

.dark .loading-spinner {
    color: #9ca3af;
}

.dark .loading-spinner::before {
    border-color: #4b5563;
    border-top-color: #3b82f6;
}

.dark .error-message {
    background: #7f1d1d;
    color: #fecaca;
    border-color: #991b1b;
}

.dark .control-button {
    background: #3b82f6;
}

.dark .control-button:hover {
    background: #2563eb;
}

.dark .control-button.secondary {
    background: #4b5563;
}

.dark .control-button.secondary:hover {
    background: #6b7280;
}

.dark .control-button.success {
    background: #059669;
}

.dark .control-button.success:hover {
    background: #047857;
}

.dark .control-button:disabled {
    background: #374151;
    color: #9ca3af;
}

/* RTL ADJUSTMENTS FOR DARK MODE */
.dark.rtl .line-numbers {
    background: #374151;
    border-left-color: #4b5563;
}

/* HIGH CONTRAST MODE FOR DARK */
@media (prefers-contrast: high) {
    .dark .code-editor-container {
        border: 2px solid #fff;
    }
    
    .dark .code-block {
        border: 1px solid #000;
    }
    
    .dark .copy-button {
        border: 1px solid #000;
    }
}