/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --bg-input: #0d1117;
    --border: #30363d;
    --border-light: #484f58;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --accent-dim: #1f6feb33;
    --green: #3fb950;
    --orange: #d29922;
    --red: #f85149;
    --purple: #bc8cff;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
    --radius: 6px;
    --radius-lg: 10px;
    --header-height: 52px;
    --toolbar-height: 44px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ===== Header ===== */
.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.3px;
}

.logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 700;
    color: #fff;
}

.stats {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn:hover {
    background: var(--border);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn:active {
    transform: scale(0.97);
}

.btn svg {
    flex-shrink: 0;
}

/* ===== Toolbar ===== */
.toolbar {
    height: var(--toolbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 2px;
    overflow-x: auto;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.toolbar-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

.toolbar-btn:active {
    background: var(--accent-dim);
    color: var(--accent);
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 6px;
    flex-shrink: 0;
}

/* ===== Editor Container ===== */
.editor-container {
    display: flex;
    height: calc(100vh - var(--header-height) - var(--toolbar-height));
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.pane-header {
    height: 36px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.pane-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.divider {
    width: 1px;
    background: var(--border);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.15s;
}

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

/* ===== Editor ===== */
.editor {
    flex: 1;
    width: 100%;
    padding: 20px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.7;
    tab-size: 4;
    overflow-y: auto;
}

.editor::placeholder {
    color: var(--text-muted);
}

.editor::-webkit-scrollbar,
.preview::-webkit-scrollbar {
    width: 8px;
}

.editor::-webkit-scrollbar-track,
.preview::-webkit-scrollbar-track {
    background: transparent;
}

.editor::-webkit-scrollbar-thumb,
.preview::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.editor::-webkit-scrollbar-thumb:hover,
.preview::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ===== Preview ===== */
.preview {
    flex: 1;
    padding: 20px 28px;
    background: var(--bg-primary);
    overflow-y: auto;
    font-size: 15px;
    line-height: 1.7;
}

.preview h1 {
    font-size: 2em;
    font-weight: 700;
    margin: 0 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.preview h2 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 24px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.preview h3 {
    font-size: 1.25em;
    font-weight: 600;
    margin: 20px 0 10px;
    color: var(--text-primary);
}

.preview h4 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 16px 0 8px;
    color: var(--text-primary);
}

.preview h5, .preview h6 {
    font-size: 1em;
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--text-secondary);
}

.preview p {
    margin: 0 0 16px;
    color: var(--text-primary);
}

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

.preview a:hover {
    text-decoration: underline;
}

.preview strong {
    font-weight: 600;
    color: var(--text-primary);
}

.preview em {
    font-style: italic;
}

.preview code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    color: var(--orange);
}

.preview pre {
    margin: 0 0 16px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
}

.preview pre code {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.6;
}

.preview blockquote {
    margin: 0 0 16px;
    padding: 4px 16px;
    border-left: 3px solid var(--accent);
    background: var(--accent-dim);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
}

.preview blockquote p {
    margin-bottom: 8px;
}

.preview blockquote p:last-child {
    margin-bottom: 0;
}

.preview ul, .preview ol {
    margin: 0 0 16px;
    padding-left: 24px;
}

.preview li {
    margin-bottom: 4px;
}

.preview li > ul, .preview li > ol {
    margin-bottom: 0;
    margin-top: 4px;
}

.preview hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 24px 0;
}

.preview img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 8px 0;
}

.preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 16px;
}

.preview th, .preview td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.preview th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

/* ===== Toast notification ===== */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 18px;
    background: var(--green);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.25s ease;
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header {
        padding: 0 10px;
    }

    .header-right .btn span,
    .btn:not(.btn-icon) {
        font-size: 0;
    }

    .btn svg {
        margin: 0;
    }

    .stats {
        display: none;
    }

    .editor-container {
        flex-direction: column;
    }

    .divider {
        width: 100%;
        height: 1px;
        cursor: row-resize;
    }

    .pane {
        flex: 1;
        min-height: 0;
    }
}

@media (max-width: 480px) {
    .toolbar {
        padding: 0 6px;
        gap: 1px;
    }

    .toolbar-btn {
        width: 28px;
        height: 28px;
    }

    .toolbar-divider {
        margin: 0 3px;
    }
}

/* ===== Selection ===== */
::selection {
    background: var(--accent-dim);
    color: var(--text-primary);
}
