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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f9fc;
    --bg-header: #121633;
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --border-color: #e3e7f1;
    --accent-color: #4f46e5;
    --accent-hover: #4338ca;
    --code-bg: #f5f7fa;
    --success-color: #10b981;
    --error-color: #ef4444;
    --luxardo-midnight: #121633;
    --luxardo-blue: #1e2451;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
}

/* Dark Theme */
body.dark-theme {
    --bg-primary: #0a0d1f;
    --bg-secondary: #121633;
    --bg-header: #0a0d1f;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --border-color: #1e2451;
    --code-bg: #1a1f3a;
    --accent-color: #6366f1;
    --accent-hover: #818cf8;
}

/* Layout */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    background: var(--bg-header);
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.toolbar .separator {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.2);
    margin: 0 0.5rem;
}

button {
    background: transparent;
    color: white;
    border: 1px solid rgba(255,255,255,0.15);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s;
    font-weight: 500;
}

button:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.25);
    transform: translateY(-1px);
}

#font-selector,
#width-selector {
    background: rgba(255,255,255,0.05);
    color: white;
    border: 1px solid rgba(255,255,255,0.15);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-weight: 500;
}

#font-selector:hover,
#width-selector:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.25);
}

#font-selector option,
#width-selector option {
    background: var(--bg-header);
    color: white;
}

button:active {
    transform: translateY(1px);
}

button svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

/* Container */
.container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    height: calc(100vh - 60px - 40px); /* Subtract header and status bar */
}

/* Editor Pane */
.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    min-width: 200px;
    overflow: hidden;
}

.CodeMirror {
    flex: 1;
    height: 100%;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
}

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

/* Resizer */
.resizer {
    width: 4px;
    background: var(--border-color);
    cursor: col-resize;
    position: relative;
    transition: all 0.2s;
}

.resizer:hover {
    background: var(--accent-color);
    width: 6px;
    margin: 0 -1px;
}

.resizer:active {
    background: var(--accent-hover);
}

/* Preview Pane */
.preview-pane {
    flex: 1;
    overflow: auto;
    background: var(--bg-primary);
    min-width: 200px;
}

#preview {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    transition: max-width 0.3s ease;
}

/* Markdown Styles */
.markdown-body {
    line-height: 1.6;
    color: var(--text-primary);
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

.markdown-body h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

.markdown-body h2 { font-size: 1.5em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body h5 { font-size: 0.875em; }
.markdown-body h6 { font-size: 0.85em; }

.markdown-body p {
    margin-bottom: 1em;
}

.markdown-body code {
    background: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 90%;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.markdown-body pre {
    background: var(--code-bg);
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;
    margin-bottom: 1em;
}

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

.markdown-body blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 1em;
    color: var(--text-secondary);
    margin-bottom: 1em;
}

.markdown-body ul, .markdown-body ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.markdown-body li {
    margin-bottom: 0.25em;
}

.markdown-body li > ul, .markdown-body li > ol {
    margin-top: 0.25em;
    margin-bottom: 0.25em;
}

.markdown-body li p {
    margin-bottom: 0.25em;
}

/* Nested blockquote styles */
.markdown-body blockquote table {
    margin-top: 0.5em;
}

.markdown-body blockquote pre {
    margin-top: 0.5em;
}

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1em;
}

.markdown-body th, .markdown-body td {
    border: 1px solid var(--border-color);
    padding: 0.5em;
    text-align: left;
}

.markdown-body th {
    background: var(--code-bg);
    font-weight: 600;
}

.markdown-body a {
    color: var(--accent-color);
    text-decoration: none;
}

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

.markdown-body img {
    max-width: 150px;
    height: auto;
    border-radius: 4px;
}

.markdown-body hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

/* Extended Markdown Features */
.markdown-body del {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.markdown-body mark {
    background: #ffeb3b;
    color: #000;
    padding: 0.1em 0.2em;
}

.markdown-body ins {
    text-decoration: underline;
    color: var(--success-color);
}

.markdown-body sub, .markdown-body sup {
    font-size: 75%;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}

.markdown-body sup { top: -0.5em; }
.markdown-body sub { bottom: -0.25em; }

/* Task Lists */
.markdown-body .task-list-item {
    list-style: none;
    margin-left: -1.5em;
}

.markdown-body .task-list-item input[type="checkbox"] {
    margin-right: 0.5em;
    vertical-align: middle;
}

/* Footnotes */
.markdown-body .footnote-ref {
    vertical-align: super;
    font-size: 0.8em;
    text-decoration: none;
}

.markdown-body .footnotes {
    font-size: 0.9em;
    border-top: 1px solid var(--border-color);
    margin-top: 2em;
    padding-top: 1em;
}

/* Math */
.markdown-body .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.5em 0;
}

.markdown-body .math-error {
    color: var(--error-color);
    background: rgba(231, 76, 60, 0.1);
    padding: 0.5em;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.markdown-body .footnotes ol {
    padding-left: 1.5em;
}

/* Status Bar */
.status-bar {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    gap: 1rem;
}

.status-bar .separator {
    color: var(--border-color);
}

/* Notification */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--success-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 1000;
    font-weight: 500;
}

.notification.show {
    transform: translateX(0);
}

.notification.error {
    background: var(--error-color);
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }
    
    .resizer {
        width: 100%;
        height: 4px;
        cursor: row-resize;
    }
    
    .editor-pane, .preview-pane {
        min-height: 200px;
        min-width: auto;
    }
    
    #preview {
        padding: 1rem;
    }
    
    .toolbar {
        flex-wrap: wrap;
    }
}

/* Print Styles */
@media print {
    .header, .status-bar, .resizer, .editor-pane {
        display: none;
    }
    
    .preview-pane {
        width: 100%;
    }
    
    #preview {
        max-width: none;
        padding: 0;
    }
}