/* Modern CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Color Variables - Material Design Dark Theme */
:root {
    /* Primary Colors */
    --bg-primary: #000000;
    --bg-secondary: #0d1117;
    --bg-tertiary: #141a22;
    --bg-quaternary: #252d38;
    
    /* Text Colors */
    --text-primary: #e0e0e0;
    --text-secondary: #757575;
    
    /* Accent Colors */
    --accent-primary: #dadada;
    --accent-primary-light: #f1f1f1;
    
    /* Material Design Colors */
    --blue: #2196f3;
    --blue-dark: #1976d2;
    --purple: #9c27b0;
    --purple-dark: #7b1fa2;
    --green: #4caf50;
    --green-dark: #388e3c;
    --orange: #ff9800;
    --orange-dark: #f57c00;
    --red: #f44336;
    --yellow: #ffc107;
    
    /* Console Colors */
    --console-error: #f44336;
    --console-error-bg: rgba(244, 67, 54, 0.1);
    --console-error-bg-hover: rgba(244, 67, 54, 0.2);
    --console-error-text: #ffcdd2;
    
    --console-warn: #ffc107;
    --console-warn-bg: rgba(255, 193, 7, 0.1);
    --console-warn-bg-hover: rgba(255, 193, 7, 0.2);
    --console-warn-text: #fff8e1;
    
    --console-info: #2196f3;
    --console-info-bg: rgba(33, 150, 243, 0.1);
    --console-info-bg-hover: rgba(33, 150, 243, 0.2);
    --console-info-text: #bbdefb;
    
    --console-success: #4caf50;
    --console-success-bg: rgba(76, 175, 80, 0.1);
    --console-success-bg-hover: rgba(76, 175, 80, 0.2);
    --console-success-text: #c8e6c9;
    
    /* Border Colors */
    --border-primary: #1f2736;
    --border-accent: rgba(134, 146, 252, 0.3);
    
    /* Accent Alpha Variants */
    --accent-alpha-10: rgba(134, 146, 252, 0.1);
    --accent-alpha-20: rgba(134, 146, 252, 0.2);
    --accent-alpha-30: rgba(134, 146, 252, 0.3);
    --accent-alpha-40: rgba(134, 146, 252, 0.4);
    --accent-alpha-50: rgba(134, 146, 252, 0.5);
    
    /* Shadow Colors */
    --shadow-light: rgba(0, 0, 0, 0.3);
    --shadow-medium: rgba(0, 0, 0, 0.4);
    --shadow-heavy: rgba(0, 0, 0, 0.6);
    --shadow-subtle: rgba(0, 0, 0, 0.1);

    
    /* Special Colors */
    --white: #ffffff;
    --clear-btn-border: rgba(244, 67, 54, 0.3);
    --clear-btn-border-hover: rgba(244, 67, 54, 0.5);
    
    /* Legacy color (to be removed eventually) */
    --legacy-blue: rgba(102, 126, 234, 1);
    --legacy-blue-shadow: rgba(102, 126, 234, 0.5);
}

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

hr {
    border: none;
    border-top: 1px solid var(--border-primary);
    margin-top: 12px;
    margin-bottom: 12px;    
}

/* Header Styles */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    padding: 10px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.title {
    font-size: 20px;
    font-weight: 500;
    color: var(--accent-primary);
    letter-spacing: 0.5px;
}

.header-buttons {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Main Container */
.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.container {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 0; /* No gap needed with split.js */
}

/* Split.js specific styles - Professional flat dark design */
.gutter {
    background-color: var(--bg-secondary);
    background-repeat: no-repeat;
    background-position: center center;
    border: none;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.gutter.gutter-horizontal {
    background-color: var(--bg-primary);
    cursor: col-resize;
    background-image: none;
    position: relative;
    overflow: hidden;
}

/* Modern grip indicator */
.gutter.gutter-horizontal::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 40px;
    background: var(--text-secondary);
    /* border-radius: 1px; */
    opacity: 0.4;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.gutter.gutter-horizontal:hover::before {
    opacity: 0.8;
    background: var(--text-primary);
}

/* Vertical gutter for console split */
.gutter.gutter-vertical {
    background-color: var(--bg-primary);
    cursor: row-resize;
    height: 6px;
    background-image: none;
    position: relative;
    overflow: hidden;
    margin-top: 3px;
    margin-bottom: 2px;
    margin-left: 2px;
    margin-right: 2px;
}

/* Modern grip indicator for vertical gutter */
.gutter.gutter-vertical::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 2px;
    background: var(--text-secondary);
    opacity: 0.4;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.gutter.gutter-vertical:hover::before {
    opacity: 0.8;
    background: var(--text-primary);
}

/* Panel Styles */
.editor-container, .preview-container {
    background: var(--bg-secondary);
    /* border-radius: 4px; */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* border: 2px solid var(--border-primary); */
}

.preview-container {
    background: var(--white); /* Keep preview light */
}

.panel-header {
    background: var(--bg-secondary);
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    font-size: 14px;
    font-weight: 500;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Smooth transitions for panel resizing */
.editor-container, .preview-container {
    transition: none; /* Remove transition during drag for smooth resizing */
}

.editor-container.resize-complete, .preview-container.resize-complete {
    transition: width 0.1s ease-out;
}

.console-container {
    transition: height 0.1s ease-out;
}

/* Prevent text selection during resize */
.no-select {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* Resize overlay styles */
#resize-overlay, #console-resize-overlay {
    background: transparent;
    pointer-events: all;
}

/* CodeMirror Overrides */
.CodeMirror {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
    border: none;
    border-radius: 0;
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

.CodeMirror-gutters {
    background: var(--bg-secondary) !important;
    border-right: 1px solid var(--border-primary) !important;
}

.CodeMirror-linenumber {
    color: var(--text-secondary) !important;
    font-size: 12px;
}

.CodeMirror-cursor {
    border-left: 1px solid var(--accent-primary) !important;
}

.CodeMirror-selected {
    background: var(--accent-alpha-20) !important;
}

.CodeMirror-focused .CodeMirror-selected {
    background: var(--accent-alpha-30) !important;
}

/* Text Area Fallback */
#code-editor {
    width: 100%;
    flex: 1;
    border: none;
    padding: 20px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Source Code Pro', Consolas, monospace;
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg-secondary);
    color: var(--text-primary);
    resize: none;
    outline: none;
}

/* Preview Iframe */
#preview-pane {
    width: 100%;
    flex: 1;
    border: none;
    background: var(--bg-secondary); /* Keep preview light */
}

/* Header Buttons */
.header-buttons .icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    text-decoration: none;
    outline: none;
    transition: all 0.2s ease;
    position: relative;
}

.header-buttons .icon-button:hover {
    transform: scale(1.2);
}

.header-buttons .icon-button svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    transition: inherit;
}

/* Console Container */
.console-container {
    background: var(--bg-secondary);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    position: relative;
}

#console-output {
    background: var(--bg-primary);
    color: var(--text-primary);
    padding-left: 10px;
    padding-top: 10px;
    padding-right: 10px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Source Code Pro', Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* Prevent overflow issues */
}

/* Modern Flat Dark Scrollbars */
/* Global scrollbar styles */
*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 0;
}

*::-webkit-scrollbar-thumb {
    background: var(--bg-quaternary);
    border-radius: 0;
    border: none;
}

*::-webkit-scrollbar-thumb:hover {
    background: #555555;
}

*::-webkit-scrollbar-thumb:active {
    background: #666666;
}

*::-webkit-scrollbar-corner {
    background: var(--bg-primary);
}

/* Specific console scrollbar with accent color */
#console-output::-webkit-scrollbar {
    width: 8px;
}

#console-output::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 0;
}

#console-output::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 0;
    border: none;
}

#console-output::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

#console-output::-webkit-scrollbar-thumb:active {
    background: var(--accent-primary-light);
}

#console-output div {
    margin-bottom: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.console-entry {
    margin-bottom: 4px;
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    font-family: inherit;
}

#console-output div:hover {
    background: var(--accent-alpha-10);
}

/* Console entry styles by level */
.console-entry.console-error {
    background: var(--console-error-bg);
    border-left-color: var(--console-error);
    color: var(--console-error-text);
}

.console-entry.console-warn {
    background: var(--console-warn-bg);
    border-left-color: var(--console-warn);
    color: var(--console-warn-text);
}

.console-entry.console-log {
    background: var(--console-info-bg);
    border-left-color: var(--console-info);
    color: var(--console-info-text);
}

.console-entry.console-info {
    background: var(--console-success-bg);
    border-left-color: var(--console-success);
    color: var(--console-success-text);
}

.console-entry.console-error:hover {
    background: var(--console-error-bg-hover);
}

.console-entry.console-warn:hover {
    background: var(--console-warn-bg-hover);
}

.console-entry.console-log:hover {
    background: var(--console-info-bg-hover);
}

.console-entry.console-info:hover {
    background: var(--console-success-bg-hover);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: var(--shadow-heavy);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 4px;
    max-width: 90%;
    width: 700px;
    max-height: 90%;
    box-shadow: 0 8px 32px var(--shadow-heavy);
    animation: slideUp 0.3s ease;
    overflow: hidden;
    border: 1px solid var(--border-primary);
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(50px) scale(0.95);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 500;
    color: var(--accent-primary);
}

.modal-actions {
    display: flex;
    gap: 8px;
}

.modal-btn {
    background: var(--accent-alpha-20);
    border: none;
    border-radius: 4px;
    padding: 8px;
    cursor: pointer;
    color: var(--accent-primary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-btn:hover {
    background: var(--accent-alpha-30);
    transform: scale(1.05);
}

.modal-btn:active {
    transform: scale(0.95);
}

.modal-body {
    padding: 24px;
    background: var(--bg-secondary);
}

.info-content p {
    margin: 12px 0;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
}

.info-content strong {
    color: var(--accent-primary);
    font-weight: 600;
    display: inline-block;
    min-width: 80px;
}

#encoded-output {
    width: 100%;
    height: 200px;
    border: 2px solid var(--border-primary);
    border-radius: 4px;
    padding: 16px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    resize: vertical;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
    word-break: break-all;
}

#encoded-output:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-alpha-20);
}

.url-section {
    margin-top: 20px;
}

.url-section h4 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
}

.url-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

#playground-url {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-primary);
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

#playground-url:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-alpha-20);
}

#copy-url, #copy-encoded {
    background: var(--accent-primary);
    color: var(--bg-primary);
    padding: 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

#copy-url:hover, #copy-encoded:hover {
    background: var(--accent-primary-light);
    transform: scale(1.05);
}

/* Link Styles */
a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
    border-radius: 3px;
    padding: 2px 4px;
    margin: -2px -4px;
}

a:hover {
    color: var(--accent-primary-light);
    text-decoration: none;
}

/* Special styling for links in modal content */
.modal-body a {
    color: var(--blue);
    font-weight: 600;
    border-radius: 4px;
}

.modal-body a:hover {
    text-decoration: underline;
    text-decoration-color: var(--blue-dark);
}

/* External link indicator */
a[target="_blank"]:after {
    content: " ↗";
    font-size: 0.8em;
    opacity: 0.7;
    margin-left: 2px;
}

/* Custom components styles */
.custom-list-group {
    display: flex;
    flex-direction: column;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-primary);
    margin-bottom: 16px;
}

.custom-list-item {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
}

.custom-list-item:last-child {
    border-bottom: none;
}

.custom-list-header {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--accent-primary);
}

/* Custom link styles */
.custom-link {
    color: var(--accent-primary) !important;
    text-decoration: none;
    transition: all 0.2s ease;
}

.custom-link:hover {
    color: var(--accent-primary-light) !important;
    text-decoration: underline;
}

/* Gallery Modal Styles */
.gallery-modal-content {
    max-width: 1200px;
    width: 90vw;
    height: 80vh;
    max-height: 900px;
    display: flex;
    flex-direction: column;
}

.gallery-body {
    display: flex;
    gap: 0px;
    flex: 1;
    min-height: 0;
    padding: 0px;
    overflow-y: auto;
}

.gallery-navigation {
    width: 300px;
    min-width: 250px;
    background: var(--bg-secondary);
    overflow-y: auto;
    padding: 16px;
}

.gallery-section-header {
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 12px;
    margin-top: 20px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gallery-section-header:first-child {
    margin-top: 0;
}

.gallery-graph-list {
    list-style: none;
    margin: 0;
    padding: 0;
    margin-bottom: 16px;
}

.gallery-graph-item {
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-size: 13px;
    margin-bottom: 4px;
}

.gallery-graph-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.gallery-graph-item.selected {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
}

.gallery-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0px;
    min-width: 0;
}

.gallery-preview {
    flex: 2;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-primary);
    overflow: hidden;
}

.gallery-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-left: 16px;
    padding-right: 16px;
    padding-top: 6px;
    padding-bottom: 6px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
}

.gallery-preview-header h3 {
    margin: 0;
    color: var(--accent-primary);
    font-size: 16px;
}

.gallery-load-button {
    margin: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: normal;
}

.gallery-load-button:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    transform: none;
}

.gallery-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.gallery-info {
    flex: 1;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    border-left: 1px solid var(--border-primary);
    padding: 20px;
    overflow-y: auto;
}

.gallery-info p {
    margin-bottom: 12px;
    line-height: 1.6;
    color: var(--text-primary);
}

.gallery-info h4 {
    color: var(--accent-primary);
    margin-bottom: 12px;
}

/* Responsive gallery layout */
@media (max-width: 768px) {
    .gallery-modal-content {
        width: 95vw;
        height: 90vh;
    }
    
    .gallery-body {
        flex-direction: column;
        gap: 16px;
    }
    
    .gallery-navigation {
        width: 100%;
        max-height: 200px;
    }
    
    .gallery-content {
        flex-direction: column;
    }
    
    .gallery-preview {
        height: 300px;
    }
}