:root {
    /* Base Dark Theme (Default) */
    --bg-dark: #0F1219;
    --bg-panel: #161A23;
    --bg-header: #11151F;
    --bg-dropdown: #1A1F2B;
    --border: #2A2E39;
    --border-hover: #3F4555;

    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --secondary: #8B5CF6;
    --accent: #22D3EE;

    --text-main: #F3F4F6;
    --text-muted: #9CA3AF;
    --text-code: #A78BFA;

    --input-bg: transparent;

    --radius: 12px;
    --radius-sm: 8px;
    --transition: 200ms ease;

    /* Markdown specific colors */
    --md-link: #818CF8;
    --md-blockquote: #374151;
    --md-code-bg: #1F2937;
    --md-hr: #374151;
    --md-table-border: #374151;
    --md-table-stripe: rgba(255, 255, 255, 0.02);
}

.theme-light {
    --bg-dark: #F9FAFB;
    --bg-panel: #FFFFFF;
    --bg-header: #F3F4F6;
    --bg-dropdown: #FFFFFF;
    --border: #E5E7EB;
    --border-hover: #D1D5DB;

    --text-main: #111827;
    --text-muted: #6B7280;
    --text-code: #6D28D9;

    --md-link: #4F46E5;
    --md-blockquote: #E5E7EB;
    --md-code-bg: #F3F4F6;
    --md-hr: #E5E7EB;
    --md-table-border: #E5E7EB;
    --md-table-stripe: rgba(0, 0, 0, 0.02);
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: background-color var(--transition), color var(--transition);
}

.hidden {
    display: none !important;
}

/* --- Top Navigation --- */
.top-nav {
    height: 60px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    background: var(--bg-panel);
    flex-shrink: 0;
    z-index: 10;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.nav-brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

.stat-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0.25rem 0.75rem;
    background: var(--bg-header);
    border-radius: 99px;
    border: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

/* --- Buttons --- */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
}

.btn.primary:hover {
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn.icon-btn {
    background: transparent;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 50%;
}

.btn.icon-btn:hover {
    background: var(--border);
    color: var(--text-main);
}

/* Dropdown */
.has-dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--bg-dropdown);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    padding: 0.5rem;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.dropdown-menu button {
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    text-align: left;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.1s;
}

.dropdown-menu button:hover {
    background: var(--border);
}

/* --- Workspace Layout --- */
.workspace {
    display: flex;
    flex: 1;
    height: calc(100vh - 60px);
    width: 100vw;
    overflow: hidden;
}

.workspace.split-horizontal {
    flex-direction: row;
}

.workspace.split-vertical {
    flex-direction: column;
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg-panel);
}

.editor-pane {
    background: var(--bg-dark);
}

.pane-header {
    height: 48px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--bg-header);
    flex-shrink: 0;
}

.pane-header h2 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Resizer */
.pane-divider {
    background: var(--border);
    position: relative;
    z-index: 5;
}

.workspace.split-horizontal .pane-divider {
    width: 6px;
    cursor: col-resize;
}

.workspace.split-vertical .pane-divider {
    height: 6px;
    cursor: row-resize;
}

.pane-divider:hover,
.pane-divider.active {
    background: var(--primary);
}

/* Editor */
#markdown-input {
    flex: 1;
    width: 100%;
    resize: none;
    border: none;
    background: transparent;
    color: var(--text-main);
    padding: 1.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    outline: none;
}

.status-indicator {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.status-indicator::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10B981;
}

.status-indicator.saving::before {
    background: #F59E0B;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from {
        opacity: 0.5;
    }

    to {
        opacity: 1;
    }
}

/* --- Preview Styles (Markdown Body) --- */
.preview-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 3rem;
    background: var(--bg-panel);
}

.markdown-body {
    -ms-text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    color: var(--text-main);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    word-wrap: break-word;
    max-width: 800px;
    margin: 0 auto;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-main);
}

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

.markdown-body h2 {
    font-size: 1.5em;
    padding-bottom: .3em;
    border-bottom: 1px solid var(--md-hr);
}

.markdown-body h3 {
    font-size: 1.25em;
}

.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre,
.markdown-body details {
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body hr {
    height: .25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--md-hr);
    border: 0;
}

.markdown-body blockquote {
    padding: 0 1em;
    color: var(--text-muted);
    border-left: .25em solid var(--md-blockquote);
}

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

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

.markdown-body code {
    padding: .2em .4em;
    margin: 0;
    font-size: 85%;
    background-color: var(--md-code-bg);
    color: var(--text-code);
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
}

.markdown-body pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--md-code-bg);
    border-radius: 6px;
}

.markdown-body pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
    border-radius: 0;
    font-size: 100%;
    word-break: normal;
    white-space: pre;
    background: transparent;
}

/* Table */
.markdown-body table {
    border-spacing: 0;
    border-collapse: collapse;
    display: block;
    width: max-content;
    max-width: 100%;
    overflow: auto;
}

.markdown-body table th,
.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid var(--md-table-border);
}

.markdown-body table tr:nth-child(2n) {
    background-color: var(--md-table-stripe);
}

.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
    background-color: var(--bg-panel);
    border-radius: var(--radius-sm);
}

/* --- TOC --- */
.toc-wrapper {
    position: relative;
}

.toc-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-dropdown);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    padding: 1rem;
    z-index: 100;
}

.toc-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

#toc-list {
    list-style: none;
    font-size: 0.85rem;
}

#toc-list li a {
    color: var(--text-main);
    text-decoration: none;
    display: block;
    padding: 0.25rem 0;
    opacity: 0.8;
    transition: opacity 0.2s;
}

#toc-list li a:hover {
    opacity: 1;
    color: var(--primary);
}

#toc-list .toc-h2 {
    padding-left: 0;
}

#toc-list .toc-h3 {
    padding-left: 1rem;
}

#toc-list .toc-h4 {
    padding-left: 2rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-main);
    color: var(--bg-dark);
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }

    .top-nav,
    .pane-header,
    .pane-divider,
    .editor-pane {
        display: none !important;
    }

    .workspace {
        height: auto;
        overflow: visible;
        display: block;
    }

    .preview-pane {
        width: 100%;
    }

    .preview-content {
        padding: 0;
        background: white;
        max-width: none;
    }

    .markdown-body {
        color: black;
    }

    .markdown-body code {
        border: 1px solid #ddd;
        background: #f8f8f8;
    }

    .markdown-body pre {
        border: 1px solid #ddd;
        background: #f8f8f8;
        page-break-inside: avoid;
    }

    .markdown-body img {
        max-width: 100%;
        page-break-inside: avoid;
    }
}