/* MoreCompute Notebook Styles - Marimo inspired */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #ffffff;
    color: #1f2937;
    line-height: 1.6;
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
    padding: 0;
    display: flex;
}

/* Kernel Status Banner */
.kernel-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: linear-gradient(180deg, #ef4444 0%, #dc2626 50%, #ffffff 100%);
    padding: 12px 20px;
    border-bottom: 1px solid #fca5a5;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    0% {
        transform: translateY(-100%);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.kernel-message {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.kernel-status-text {
    font-weight: 600;
    font-size: 14px;
    color: #ffffff;
    margin-bottom: 2px;
}

.kernel-subtitle {
    font-size: 12px;
    color: #fecaca;
}

/* Kernel Status Bar */
.kernel-status-bar {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.kernel-status-indicator {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    padding: 8px 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(8px);
    font-size: 12px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    transition: background-color 0.3s ease;
}

.status-dot.connecting {
    background-color: #fbbf24;
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background-color: #10b981;
}

.status-dot.disconnected {
    background-color: #ef4444;
}

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

.status-text {
    color: #6b7280;
}

/* Notebook Wrapper */
.notebook-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
}

.notebook {
    position: relative;
}

/* Empty State */
.empty-state {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* Add Cell Lines */
.add-cell-line {
    position: relative;
    height: 0;
    width: 100%;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 10;
    pointer-events: none; /* Don't block interactions by default */
}

.add-cell-line:hover {
    opacity: 1;
    pointer-events: auto; /* Re-enable interactions on hover */
}

.add-cell-line::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 20px;
    background: transparent;
    pointer-events: auto; /* Allow hover detection */
}

/* Extra padding for top cell hover area */
.add-line-above::before {
    height: 28px;
    top: -14px;
    left: 50px;
    right: 50px;
}

/* Extended hover area for add-line-below to capture hover below cells */
.add-line-below::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 16px; /* Smaller hover area to avoid blocking cell clicks */
    background: transparent;
    pointer-events: auto; /* Allow hover detection */
}

.add-cell-line::after {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: #3b82f6;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.add-cell-line:hover::after {
    opacity: 1;
}

.add-cell-button {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: auto;
}

.add-cell-line:hover .add-cell-button {
    opacity: 1;
}

.add-cell-button img {
    width: 14px;
    height: 14px;
    filter: brightness(0) invert(1);
}

.cell-type-menu {
    display: flex;
    flex-direction: row;
    gap: 16px;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 20;
}

.add-cell-line:hover .cell-type-menu {
    opacity: 1;
    pointer-events: auto;
}

/* Create hover area that includes both button and menu */
.add-cell-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: -20px;
    right: -20px;
    bottom: -40px;
    z-index: 19;
}

.cell-type-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid #DBC7A8;
    background: #F4EEE7;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    color: #575042;
}

.cell-type-option:hover {
    background: #F4EEE7;
    cursor: pointer;
}

/* Cell Wrapper */
.cell-wrapper {
    position: relative;
    margin: 0;
}

/* Main Cell */
.cell {
    position: relative;
    margin: 20px 0;
    padding: 0;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: all 0.2s ease;
    overflow: hidden;
}

.cell:hover {
    border-color: #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.cell.active {
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px #3b82f6;
}

/* Cell Hover Controls */
.cell-hover-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 15;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cell:hover .cell-hover-controls {
    opacity: 1;
}

.cell-actions-right {
    display: flex;
    gap: 4px;
    align-items: center;
}

.cell-action {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(8px);
}

.cell-action:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.cell-action.run-cell-btn:hover {
    background: #dcfdf4;
}

.cell-action.delete-cell-btn:hover {
    background: #fef2f2;
}

.cell-action.run-cell-btn.stop-mode {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.cell-action.run-cell-btn.stop-mode:hover {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.cell-action img {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

.cell-action:hover img {
    opacity: 1;
}

/* Cell Content */
.cell-content {
    position: relative;
}

.cell-input {
    padding: 0;
}

.cell-editor-container {
    position: relative;
}

.cell-editor {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    padding: 16px 20px;
    background: transparent;
    color: #1f2937;
    min-height: 100px;
}

.cell-editor:focus {
    outline: none;
}

/* CodeMirror Styling */
.CodeMirror {
    height: auto;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    border: none;
    background: transparent;
    color: #1f2937;
}

.CodeMirror-focused {
    outline: none;
}

.CodeMirror-scroll {
    /* Content-based sizing - start small and grow with content */
    min-height: 32px;  /* Single line minimum */
    padding: 8px 16px;
    transition: min-height 0.2s ease;
}

/* Auto-sizing based on content */
.CodeMirror {
    /* Let CodeMirror size itself based on content */
    height: auto !important;
    min-height: 32px;
}

.CodeMirror-sizer {
    min-height: auto !important;
}

/* Smart sizing classes applied dynamically */
.cell.cell-empty .CodeMirror-scroll {
    min-height: 32px;  /* Very compact for empty cells */
}

.cell.cell-single-line .CodeMirror-scroll {
    min-height: 40px;  /* Slightly more space for single line */
}

.cell.cell-focused .CodeMirror-scroll {
    min-height: 48px;  /* More space when focused for editing */
}

.CodeMirror-cursor {
    border-left: 2px solid #3b82f6;
}

.CodeMirror-selected {
    background: #dbeafe;
}

.CodeMirror-line {
    padding: 0;
}

.CodeMirror-placeholder {
    color: #9ca3af !important;
    font-style: italic;
}

/* Line numbers styling */
.CodeMirror-linenumbers {
    background: #f9fafb;
    border-right: 1px solid #e5e7eb;
    padding-right: 8px;
    min-width: 30px;
}

.CodeMirror-linenumber {
    color: #9ca3af;
    font-size: 11px;
    text-align: right;
    padding: 0 5px 0 0;
    min-width: 20px;
}

.CodeMirror-gutters {
    background: #f9fafb;
    border-right: 1px solid #e5e7eb;
}

/* Markdown Rendered Content - Auto-sizing */
.markdown-rendered {
    padding: 8px 16px;
    line-height: 1.7;
    color: #1f2937;
    cursor: pointer;
    min-height: auto;  /* Let content determine height */
}

/* Smart sizing for markdown content */
.cell.cell-empty .markdown-rendered,
.cell.cell-empty .text-cell-output {
    min-height: 24px;  /* Very compact for empty markdown */
    padding: 4px 12px;
}

.cell.cell-single-line .markdown-rendered,
.cell.cell-single-line .text-cell-output {
    min-height: 32px;  /* Single line markdown */
    padding: 6px 14px;
}

.markdown-rendered:hover {
    background: rgba(59, 130, 246, 0.02);
}

.markdown-rendered h1, .markdown-rendered h2, .markdown-rendered h3, 
.markdown-rendered h4, .markdown-rendered h5, .markdown-rendered h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    color: #111827;
}

.markdown-rendered h1 { font-size: 1.5em; }
.markdown-rendered h2 { font-size: 1.3em; }
.markdown-rendered h3 { font-size: 1.1em; }

.markdown-rendered p {
    margin: 8px 0;
}

.markdown-rendered ul, .markdown-rendered ol {
    margin: 8px 0;
    padding-left: 20px;
}

.markdown-rendered li {
    margin: 4px 0;
}

.markdown-rendered code {
    background: #f3f4f6;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.9em;
}

.markdown-rendered pre {
    background: #f9fafb;
    padding: 12px;
    border-radius: 6px;
    margin: 12px 0;
    overflow-x: auto;
}

.markdown-rendered pre code {
    background: none;
    padding: 0;
}

.markdown-rendered blockquote {
    border-left: 3px solid #d1d5db;
    padding-left: 12px;
    margin: 12px 0;
    color: #6b7280;
    font-style: italic;
}

.markdown-rendered a {
    color: #3b82f6;
    text-decoration: none;
}

.markdown-rendered a:hover {
    text-decoration: underline;
}

.markdown-rendered .empty-markdown {
    color: #9ca3af;
    font-style: italic;
}

/* Execution Indicator */
.execution-indicator {
    position: absolute;
    top: 16px;
    left: -40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 11px;
    color: #6b7280;
    width: 30px;
}

.execution-count {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 10px;
    color: #9ca3af;
}

.execution-time {
    font-size: 9px;
    color: #d1d5db;
    margin-top: 2px;
}

/* Execution Status Icon */
.execution-status {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 16;
    opacity: 0;
    animation: fadeInStatus 0.3s ease forwards;
}

@keyframes fadeInStatus {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.status-icon {
    width: 16px;
    height: 16px;
    display: block;
}

/* Cell Output */
.cell-output {
    border-top: 1px solid #f3f4f6;
    background: #fafafa;
}

.output-content {
    padding: 16px 20px;
}

.output-stream {
    background: #f9fafb;
    padding: 12px 16px;
    margin: 8px 0;
    border-radius: 6px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-wrap: break-word;
    border-left: 3px solid #e5e7eb;
}

.output-stream.stdout {
    color: #374151;
    border-left-color: #6b7280;
}

.output-stream.stderr {
    color: #dc2626;
    background: #fef2f2;
    border-left-color: #ef4444;
}

.output-result {
    background: #ffffff;
    padding: 12px 16px;
    margin: 8px 0;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.output-error {
    background: #fef2f2;
    color: #dc2626;
    padding: 12px 16px;
    margin: 8px 0;
    border-radius: 6px;
    border: 1px solid #fecaca;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Executing State */
.cell.executing {
    border-color: #fbbf24;
    background: linear-gradient(90deg, #fffbeb 0%, #ffffff 100%);
}

.cell.executing .execution-count {
    color: #f59e0b;
}

.cell.executing .execution-count::after {
    content: ' •';
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* Drag and Drop */
.sortable-ghost {
    opacity: 0.4;
}

.sortable-drag {
    transform: rotate(5deg);
    z-index: 1000;
}

/* Responsive */
@media (max-width: 768px) {
    .notebook-wrapper {
        padding: 20px 10px;
        max-width: 100%;
    }
    
    .execution-indicator {
        display: none;
    }
    
    .cell-hover-controls {
        position: relative;
        top: auto;
        right: auto;
        opacity: 1;
        padding: 8px 12px;
        background: #f9fafb;
        border-bottom: 1px solid #e5e7eb;
        justify-content: flex-end;
    }
}

/* Sidebar Styles */
.sidebar {
    width: 60px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 16px 0;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
}

.sidebar-item {
    position: relative;
    width: 48px;
    height: 48px;
    margin: 4px auto;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-item:hover {
    background: #e2e8f0;
}

.sidebar-item.active {
    background: #3b82f6;
}

.sidebar-item.active .sidebar-icon {
    filter: brightness(0) invert(1);
}

.sidebar-icon {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.sidebar-item:hover .sidebar-icon {
    opacity: 1;
}

.sidebar-tooltip {
    position: absolute;
    left: 60px;
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: white;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1000;
}

.sidebar-item:hover .sidebar-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Main content adjustment */
.main-content {
    flex: 1;
    margin-left: 60px;
}

/* Popup Overlay */
.popup-overlay {
    position: fixed;
    left: 60px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: white;
    border-right: 1px solid #e2e8f0;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 40;
    overflow-y: auto;
}

/* Popup Content */
.popup-content {
    padding: 20px;
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.popup-title {
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
}

.popup-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.popup-close:hover {
    background: #f3f4f6;
    color: #374151;
}

/* File Browser Styles */
.file-tree {
    font-size: 14px;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.file-item:hover {
    background: #f3f4f6;
}

.file-icon {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    opacity: 0.7;
}

.file-name {
    color: #374151;
}

/* Python Environment Styles */
.python-env-list {
    max-height: 300px;
    overflow-y: auto;
}

.env-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin: 8px 0;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.env-item:hover {
    border-color: #3b82f6;
    background: #f8fafc;
}

.env-item.active {
    border-color: #3b82f6;
    background: #eff6ff;
}

.env-info {
    display: flex;
    flex-direction: column;
}

.env-name {
    font-weight: 500;
    color: #1f2937;
}

.env-path {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

.env-version {
    font-size: 12px;
    color: #3b82f6;
    font-weight: 500;
}

/* Settings Editor Styles */
.settings-editor {
    width: 100%;
    height: 400px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 12px;
    resize: vertical;
    background: #f9fafb;
}

.settings-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

/* Metrics Popup Styles */
.metrics-container {
    font-size: 14px;
}

.metrics-placeholder {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

.metrics-placeholder h3 {
    font-size: 24px;
    margin-bottom: 16px;
    color: #1f2937;
}

.metrics-placeholder p {
    margin-bottom: 24px;
    font-size: 16px;
}

.coming-soon {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 24px;
    margin: 20px 0;
}

.coming-soon ul {
    list-style: none;
    padding: 0;
    margin: 16px 0;
}

.coming-soon li {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #374151;
}

.coming-soon li:last-child {
    border-bottom: none;
}

.coming-soon p:last-child {
    margin-top: 20px;
    font-style: italic;
    color: #9ca3af;
    font-size: 14px;
}
