/* NanoVM Editor - Custom Styles */

/* Global */
html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

/* Main layout */
.main-content {
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 56px - 28px); /* navbar + status bar */
}

/* Navbar adjustments */
.navbar {
    flex-shrink: 0;
}

/* Editor column - needs height constraint for proper scrolling */
.col-md-8.d-flex.flex-column {
    height: 100%;
    overflow: hidden;
}

/* Editor container - height: 0 + flex-grow creates proper constraint */
#editor-container {
    position: relative;
    height: 0;
    flex-grow: 1;
    overflow: hidden;
}

/* CodeMirror styling */
.CodeMirror {
    height: 100% !important;
    font-family: 'Fira Code', 'Source Code Pro', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.5;
}

/* Ensure CodeMirror scroll container works */
.CodeMirror-scroll {
    overflow-y: auto !important;
    overflow-x: auto !important;
}

/* Dark theme adjustments for CodeMirror */
.CodeMirror.cm-s-monokai {
    background-color: #1e1e1e;
}

/* Syntax highlighting fixes for NanoC */
.cm-s-monokai span.cm-meta {
    color: #75715e;  /* Dark grey for preprocessor directives (#include, #define) */
}

.cm-s-monokai span.cm-keyword {
    color: #f92672;  /* Pink for keywords (typedef, struct, if, for, etc.) */
}

.cm-s-monokai span.cm-type {
    color: #66d9ef;  /* Cyan for types (int, void, char, etc.) */
    font-style: italic;
}

.cm-s-monokai span.cm-qualifier {
    color: #66d9ef;  /* Cyan for qualifiers */
}

.cm-s-monokai span.cm-builtin {
    color: #66d9ef;  /* Cyan for built-in types */
}

.cm-s-monokai span.cm-def {
    color: #a6e22e;  /* Green for definitions (function names) */
}

.cm-s-monokai span.cm-variable {
    color: #f8f8f2;  /* White for variables */
}

.cm-s-monokai span.cm-variable-2 {
    color: #9effff;  /* Light cyan for variable-2 */
}

.cm-s-monokai span.cm-string {
    color: #e6db74;  /* Yellow for strings */
}

.cm-s-monokai span.cm-string-2 {
    color: #e6db74;  /* Yellow for include paths <...> */
}

.cm-s-monokai span.cm-number {
    color: #ae81ff;  /* Purple for numbers */
}

.cm-s-monokai span.cm-comment {
    color: #75715e;  /* Gray for comments */
}

.cm-s-monokai span.cm-operator {
    color: #f92672;  /* Pink for operators */
}

.cm-s-monokai span.cm-atom {
    color: #ae81ff;  /* Purple for atoms (true, false, null) */
}

.cm-s-monokai span.cm-attribute {
    color: #a6e22e;  /* Green for attributes (@syscall) */
}

/* Error line highlighting */
.error-line {
    background-color: rgba(255, 0, 0, 0.15) !important;
}

/* Error gutter marker */
.error-marker {
    color: #ff5555;
    font-weight: bold;
}

/* Toolbar */
.toolbar {
    flex-shrink: 0;
}

/* Output panels */
.output-panel {
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Fix flex container height constraints for proper scrolling */
/* The key is height: 0 + flex-grow: 1 creates a proper constraint */

/* Output column */
.col-md-4.d-flex.flex-column {
    height: 100%;
    overflow: hidden;
}

/* Tab content container */
.tab-content.flex-grow-1 {
    height: 0;
    flex-grow: 1;
    overflow: hidden;
}

/* Individual tab panes */
.tab-content > .tab-pane.flex-grow-1 {
    height: 0;
    flex-grow: 1;
    overflow: hidden;
    justify-content: flex-start;
    align-items: stretch;
}

/* Hide inactive tab panes completely */
.tab-content > .tab-pane:not(.show) {
    display: none !important;
}

/* Serial and compiler output - scrollable areas */
#serial-output,
#compiler-output {
    height: 0;
    flex-grow: 1;
    overflow-y: auto !important;
    overflow-x: hidden;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: flex-start !important;
}

/* Content inside output panels should stack from top */
#serial-output > *,
#compiler-output > * {
    flex-shrink: 0;
    width: 100%;
}

.output-panel .error {
    color: #ff6b6b;
}

.output-panel .success {
    color: #51cf66;
}

.output-panel .warning {
    color: #fcc419;
}

.output-panel .info {
    color: #74c0fc;
}

.output-panel .timestamp {
    color: #868e96;
}

.output-panel .debug-log {
    color: #adb5bd;
    font-style: italic;
}

/* Serial monitor */
.serial-input-bar {
    flex-shrink: 0;
}

#serial-output {
    scroll-behavior: smooth;
}

/* Status bar */
.status-bar {
    flex-shrink: 0;
    font-size: 12px;
    height: 28px;
}

/* Tab styling */
.nav-tabs {
    border-bottom: 1px solid #495057;
}

.nav-tabs .nav-link {
    color: #adb5bd;
    border: none;
    border-radius: 0;
    padding: 0.5rem 1rem;
}

.nav-tabs .nav-link:hover {
    color: #fff;
    border: none;
}

.nav-tabs .nav-link.active {
    color: #fff;
    background-color: #343a40;
    border: none;
    border-bottom: 2px solid #0d6efd;
}

/* Connection status */
#connection-status.connected {
    background-color: #198754 !important;
}

#connection-status.disconnected {
    background-color: #6c757d !important;
}

#connection-status.connecting {
    background-color: #ffc107 !important;
    color: #000 !important;
}

/* Compile status indicator dot */
.compile-status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.compile-status-dot.status-empty {
    background-color: #6c757d;
}

.compile-status-dot.status-dirty {
    background-color: #6c757d;
}

.compile-status-dot.status-compiling {
    background-color: #ffc107;
    animation: pulse 1s ease-in-out infinite;
}

.compile-status-dot.status-error {
    background-color: #dc3545;
}

.compile-status-dot.status-ready {
    background-color: #198754;
}

.compile-status-dot.status-running {
    background-color: #0d6efd;
    animation: pulse 1s ease-in-out infinite;
}

.compile-status-dot.status-debugging {
    background-color: #0dcaf0;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Legacy compile status (for badge) */
#compile-status.compiling {
    background-color: #0d6efd !important;
}

#compile-status.success {
    background-color: #198754 !important;
}

#compile-status.error {
    background-color: #dc3545 !important;
}

/* Device info in status bar */
.device-info {
    font-size: 0.85rem;
    color: #adb5bd;
}

.device-info .platform {
    color: #20c997;
    font-weight: 500;
}

.device-info .memory {
    font-size: 0.8rem;
}

.status-separator {
    color: #6c757d;
    font-size: 0.8rem;
}

/* Debug line highlighting */
.debug-current-line {
    background-color: rgba(255, 255, 0, 0.2) !important;
}

.debug-current-gutter {
    color: #ffc107 !important;
    font-weight: bold;
}

/* Debug arrow marker in gutter */
.debug-arrow {
    color: #ffc107;
    font-size: 12px;
}

/* Breakpoint marker (future enhancement) */
.breakpoint-marker {
    color: #dc3545;
    font-size: 10px;
}

/* Disabled button styling */
.toolbar .btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Form controls dark theme */
.form-select.bg-dark:focus,
.form-control.bg-dark:focus {
    background-color: #2d2d2d;
    border-color: #495057;
    color: #fff;
    box-shadow: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #1e1e1e;
}

::-webkit-scrollbar-thumb {
    background: #495057;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #6c757d;
}

/* Modal dark theme adjustments */
.modal-content.bg-dark {
    border-color: #495057;
}

/* Button loading state */
.btn.loading {
    pointer-events: none;
    opacity: 0.7;
}

.btn.loading::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column !important;
    }

    .main-content > .col-md-8,
    .main-content > .col-md-4 {
        width: 100%;
        height: 50%;
    }
}

/* Print styling - hide UI elements */
@media print {
    .navbar, .toolbar, .status-bar, .nav-tabs, .serial-input-bar {
        display: none !important;
    }

    .main-content {
        height: auto !important;
    }

    .CodeMirror {
        height: auto !important;
    }
}

/* ============================================
   File Browser Sidebar
   ============================================ */

/* Sidebar container */
.sidebar {
    width: 220px;
    min-width: 220px;
    max-width: 220px;
    height: 100%;
    overflow: hidden;
    transition: width 0.2s ease, min-width 0.2s ease, opacity 0.2s ease;
    background-color: #1e1e1e;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    opacity: 0;
}

/* Collapsed state toggle button */
.sidebar-collapsed {
    width: 32px;
    min-width: 32px;
    display: flex;
    align-items: flex-start;
    padding-top: 8px;
    background-color: #1e1e1e;
}

/* Sidebar header */
.sidebar-header {
    flex-shrink: 0;
    background-color: #252526;
    min-height: 40px;
}

.project-name-editable {
    font-size: 14px;
    font-weight: 500;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: text;
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-block;
    color: #e9ecef;
}

.project-name-editable:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.project-name-editable:focus {
    outline: 1px solid #0d6efd;
    background-color: #1e1e1e;
}

.project-name-editable:empty::before {
    content: 'Untitled';
    color: #666;
}

/* File list */
.file-list {
    background-color: #1e1e1e;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background-color 0.15s;
    user-select: none;
}

.file-item:hover {
    background-color: #2a2d2e;
}

.file-item.active {
    background-color: #37373d;
    border-left-color: #0d6efd;
}

.file-item .file-icon {
    width: 16px;
    margin-right: 8px;
    font-size: 14px;
    flex-shrink: 0;
}

.file-item .file-icon.main-file {
    color: #ffc107;
}

.file-item .file-icon.header-file {
    color: #17a2b8;
}

.file-item .file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: #ccc;
}

.file-item.active .file-name {
    color: #fff;
}

.file-item .file-actions {
    display: none;
    gap: 2px;
    margin-left: 4px;
}

.file-item:hover .file-actions {
    display: flex;
}

.file-item .file-actions button {
    padding: 2px 4px;
    font-size: 11px;
    line-height: 1;
    opacity: 0.6;
    border: none;
    background: transparent;
    color: #adb5bd;
}

.file-item .file-actions button:hover {
    opacity: 1;
    color: #fff;
}

.file-item .file-actions button.delete-btn:hover {
    color: #dc3545;
}

/* Sidebar footer */
.sidebar-footer {
    flex-shrink: 0;
    background-color: #252526;
}

/* Drag-drop highlight */
.sidebar.drag-over {
    background-color: rgba(13, 110, 253, 0.1);
    outline: 2px dashed #0d6efd;
    outline-offset: -2px;
}

/* Output column (Serial Monitor) */
.output-column {
    width: 320px;
    min-width: 280px;
    max-width: 400px;
    height: 100%;
    overflow: hidden;
}

.output-header {
    flex-shrink: 0;
    font-size: 14px;
    background-color: #252526;
}

/* ============================================
   Display Panel (Web VM)
   ============================================ */

.display-panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background-color: #1e1e1e;
    border-bottom: 1px solid #495057;
}

.display-panel-header {
    background-color: #252526;
    font-size: 14px;
    flex-shrink: 0;
}

.display-canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
    padding: 8px;
    aspect-ratio: 1 / 1;
    max-width: 100%;
}

#vm-display {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    width: 100%;
    height: 100%;
    border: 1px solid #333;
    aspect-ratio: 1 / 1;
    object-fit: contain;
}

.gpio-btn {
    font-size: 10px;
    padding: 1px 5px;
    line-height: 1;
    min-width: 24px;
}

/* ============================================
   Debug Panel
   ============================================ */

.debug-panel {
    flex-shrink: 0;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    background-color: #1e1e1e;
    border-bottom: 1px solid #495057;
}

.debug-panel-header {
    background-color: #252526;
    font-size: 14px;
    flex-shrink: 0;
}

.debug-panel-content {
    overflow-y: auto;
    flex: 1;
    background-color: #1e1e1e;
}

.debug-panel-content.collapsed {
    max-height: 0;
    overflow: hidden;
}

.debug-section {
    padding: 6px 10px;
    border-bottom: 1px solid #333;
}

.debug-section:last-child {
    border-bottom: none;
}

.debug-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    margin-bottom: 4px;
    font-weight: 600;
}

.debug-section-content {
    font-family: 'Fira Code', 'Source Code Pro', 'Consolas', monospace;
    font-size: 12px;
}

/* Call stack frame */
.debug-frame {
    padding: 3px 6px;
    margin: 1px 0;
    border-radius: 3px;
}

.debug-frame-current {
    background-color: #264f78;
}

.debug-frame-name {
    color: #dcdcaa;
}

.debug-frame-line {
    color: #888;
    font-size: 11px;
}

/* Variable display */
.debug-var {
    display: flex;
    align-items: baseline;
    padding: 2px 0;
    gap: 4px;
    flex-wrap: wrap;
}

.debug-var-section {
    font-size: 10px;
    text-transform: uppercase;
    color: #666;
    margin-top: 8px;
    margin-bottom: 2px;
    padding-left: 2px;
}

.debug-var-section:first-child {
    margin-top: 0;
}

.debug-var-name {
    color: #9cdcfe;
}

.debug-var-type {
    color: #666;
    font-size: 11px;
}

.debug-var-eq {
    color: #666;
}

.debug-var-value {
    color: #ce9178;
}

/* Status bar items */
.status-text {
    font-size: 12px;
    color: #adb5bd;
}

.status-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.status-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.status-item.status-errors {
    color: #dc3545;
}

.status-item.status-warnings {
    color: #ffc107;
}

/* Compiler output in modal */
.compiler-output-content {
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.compiler-output-content .error-line {
    color: #ff6b6b;
    cursor: pointer;
}

.compiler-output-content .error-line:hover {
    text-decoration: underline;
}

.compiler-output-content .warning-line {
    color: #fcc419;
    cursor: pointer;
}

.compiler-output-content .warning-line:hover {
    text-decoration: underline;
}

/* ============================================
   Responsive adjustments for sidebar
   ============================================ */

@media (max-width: 992px) {
    .sidebar {
        width: 180px;
        min-width: 180px;
        max-width: 180px;
    }

    .output-column {
        width: 260px;
        min-width: 220px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 56px; /* Below navbar */
        bottom: 28px; /* Above status bar */
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .output-column {
        position: absolute;
        right: 0;
        top: 56px;
        bottom: 28px;
        width: 100%;
        max-width: 100%;
        z-index: 999;
        display: none;
    }
}
