/* ========== Editor Layout ========== */
.editor {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 65px);
    max-width: 100%;
    margin: -32px -24px -64px;
}

.editor__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.editor__toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.editor__toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.editor__title-input {
    flex: 1;
    padding: 6px 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    min-width: 120px;
}

.editor__title-input:focus {
    border-color: var(--accent);
}

.editor__status {
    font-size: 0.8rem;
    white-space: nowrap;
}

.editor__status--saving { color: var(--accent); }
.editor__status--saved  { color: #2ea043; }
.editor__status--error  { color: #e74c3c; }
.editor__status--dirty  { color: var(--text-muted); }

/* ========== Mode switcher ========== */
.editor__modes {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 2px;
    gap: 1px;
    flex-shrink: 0;
}

.editor__mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border: none;
    border-radius: 5px;
    background: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: color .15s, background .15s;
    white-space: nowrap;
}

.editor__mode-btn:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.editor__mode-btn--active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] .editor__mode-btn--active {
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ========== Format Bar (visual mode only) ========== */
.editor__format-bar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 5px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.editor__format-bar::-webkit-scrollbar { display: none; }

.editor__format-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 26px;
    padding: 0 6px;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: color .12s, background .12s, border-color .12s;
    white-space: nowrap;
    line-height: 1;
    flex-shrink: 0;
    user-select: none;
}

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

.editor__format-btn:active {
    color: var(--accent);
    border-color: var(--accent);
}

.editor__format-btn--b    { font-weight: 700; }
.editor__format-btn--i    { font-style: italic; }
.editor__format-btn--s    { text-decoration: line-through; }
.editor__format-btn--mono { font-family: 'SFMono-Regular', Consolas, monospace; }

.editor__format-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}

/* ========== Editor Body (split pane) ========== */
.editor__body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.editor__pane {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

.editor__pane--source {
    display: flex;
}

.editor__pane--preview {
    padding: 32px 40px;
    background: var(--bg-primary);
}

/* Visual mode: preview pane fills full width, contenteditable */
#editorPreview[contenteditable] {
    outline: none;
    cursor: text;
    min-height: 100%;
}

.editor__textarea {
    width: 100%;
    height: 100%;
    padding: 24px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 14px;
    line-height: 1.6;
    tab-size: 4;
}

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

.editor__divider {
    width: 1px;
    background: var(--border);
    flex-shrink: 0;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .editor__body {
        flex-direction: column;
    }

    .editor__divider {
        width: 100%;
        height: 1px;
    }

    .editor__pane {
        flex: none;
        height: 50%;
    }

    .editor__modes {
        display: none; /* collapse on mobile */
    }

    .editor__toolbar-left {
        flex-wrap: wrap;
    }

    .editor__title-input {
        min-width: 80px;
    }
}
