:root {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --accent-color: #0d6efd;
    --preview-bg: #ffffff;
    --preview-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --bg-primary: #1a1d21;
    --bg-secondary: #212529;
    --text-primary: #f8f9fa;
    --text-secondary: #adb5bd;
    --border-color: #343a40;
    --accent-color: #0d6efd;
    --preview-bg: #212529;
    --preview-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.m2i-container {
    height: calc(100vh - 60px); /* Adjust based on header height */
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* Sidebar / Toolbar */
.m2i-sidebar {
    width: 300px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.m2i-sidebar-header,
.m2i-panel-header {
    height: 60px; /* Same as header height */
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    background: white;
    justify-content: space-between;
}

.m2i-controls {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.control-group {
    margin-bottom: 1.5rem;
}

.control-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.theme-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.theme-btn {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.theme-btn.active {
    border-color: var(--accent-color);
    transform: scale(1.1);
}

/* Main Area */
.m2i-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    margin: 0 !important;
    padding: 0 !important;
}

/* Editor & Preview Wrapper */
.m2i-workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* Editor */
.m2i-editor, .m2i-preview-pane {
    flex: 1;
    height: 100%;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.m2i-editor {
    border-right: 1px solid var(--border-color);
    background: white;
}

.m2i-editor textarea {
    flex: 1;
    width: 100%;
    resize: none;
    border: none;
    padding: 1.5rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.6;
}

.m2i-editor textarea:focus {
    outline: none;
}

/* Preview Area */
.m2i-preview-area {
    flex: 1;
    background-color: #e9ecef; /* Neutral background for contrast */
    padding: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    background-image: 
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

[data-theme="dark"] .m2i-preview-area {
    background-color: #121212;
    background-image: 
        linear-gradient(45deg, #1a1a1a 25%, transparent 25%), 
        linear-gradient(-45deg, #1a1a1a 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #1a1a1a 75%), 
        linear-gradient(-45deg, transparent 75%, #1a1a1a 75%);
}

#capture-node {
    padding: 2rem;
    border-radius: 8px; /* Default */
    background-color: white;
    box-shadow: var(--preview-shadow);
    max-width: 800px;
    width: 100%;
    min-height: 400px;
    transition: all 0.3s ease;
}

/* Window Controls (Mac Style) */
.window-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 1.5rem;
    opacity: 0; /* Hidden by default */
}

.window-controls.visible {
    opacity: 1;
}

.window-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot-red { background-color: #ff5f56; }
.dot-yellow { background-color: #ffbd2e; }
.dot-green { background-color: #27c93f; }

/* Markdown Content Styling Override */
.markdown-body {
    background: transparent !important;
    font-family: inherit !important;
}

#capture-node .markdown-body {
    background-color: transparent !important;
    color: inherit; /* Allow text color to come from theme */
}

/* Ensure code blocks look okay on different backgrounds */
#capture-node.solid-dark .markdown-body pre,
#capture-node.gradient-1 .markdown-body pre,
#capture-node.gradient-2 .markdown-body pre,
#capture-node.gradient-3 .markdown-body pre {
    background-color: rgba(0,0,0,0.3);
    color: #e6edf3;
}

/* Gradient Themes */
.gradient-1 { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
.gradient-2 { background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%); color: #333; }
.gradient-3 { background: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%); color: #333; }
.solid-dark { background-color: #1a1d21; color: #f8f9fa; }
.solid-light { background-color: #ffffff; color: #212529; }

/* Responsive */
@media (max-width: 768px) {
    .m2i-workspace {
        flex-direction: column;
    }
    
    .m2i-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        order: 2; /* Move below on mobile */
    }

    .m2i-editor {
        height: 30vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .m2i-preview-area {
        height: 40vh;
    }
}
