/* ========== Редактор заметок ========== */

.add-post-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 0 48px;
    animation: pageFadeIn var(--duration-slow) var(--ease-out);
}

@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.add-post-header {
    margin-bottom: 24px;
}

.add-post-title {
    margin: 0 0 6px;
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--color-heading);
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.add-post-subtitle {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--color-text-muted);
}

.add-post-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    overflow: hidden;
}

.add-post-success {
    margin: 16px 24px 0;
    padding: 12px 16px;
    background: #ecfdf5;
    color: var(--color-success-hover);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    animation: slideIn var(--duration-normal) var(--ease-out);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.add-post-form {
    padding: 24px;
}

.add-post-meta {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 20px;
    margin-bottom: 24px;
}

.add-post-field label,
.add-post-content-section > label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
}

.add-post-field input[type="text"],
.add-post-field select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
    font-family: var(--font-sans);
}

.add-post-field input[type="text"]:focus,
.add-post-field select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-glow);
}

.add-post-field input[type="text"]::placeholder {
    color: var(--color-text-subtle);
}

.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 0.8125rem;
    color: var(--color-text-subtle);
}

.add-post-content-section {
    margin-bottom: 20px;
}

.add-post-content-section > label {
    margin-bottom: 12px;
}

/* Тулбар */
.add-post-toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(180deg, var(--color-bg-subtle) 0%, var(--color-bg) 100%);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    margin-bottom: 12px;
}

.toolbar-section {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.toolbar-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.quick-code-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.quick-code-btn {
    padding: 6px 12px;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font-mono);
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
}

.quick-code-btn:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    color: var(--color-primary-hover);
    transform: translateY(-1px);
}

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

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.toolbar-btn {
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font-sans);
    transition: all var(--duration-fast) var(--ease-out);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.toolbar-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.toolbar-btn-primary { background: var(--color-primary); color: white; }
.toolbar-btn-primary:hover { background: var(--color-primary-hover); }
.toolbar-btn-secondary { background: #64748b; color: white; }
.toolbar-btn-secondary:hover { background: #475569; }
.toolbar-btn-success { background: var(--color-success); color: white; }
.toolbar-btn-success:hover { background: var(--color-success-hover); }
.toolbar-btn-link { background: var(--color-accent); color: white; }
.toolbar-btn-link:hover { background: #7c3aed; }
.toolbar-btn-image { background: var(--color-success); color: white; }
.toolbar-btn-image:hover { background: var(--color-success-hover); }

.toolbar-btn-checklist { background: #8b5cf6; color: white; }
.toolbar-btn-checklist:hover { background: #7c3aed; }

.toolbar-select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-sans);
}

/* Переключатель режима просмотра */
.editor-view-toggle {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--color-bg);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    margin-bottom: 12px;
    width: fit-content;
}

.view-mode-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font-sans);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.view-mode-btn:hover {
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.6);
}

.view-mode-btn.active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

/* Рабочая область редактора */
.editor-workspace {
    display: grid;
    gap: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-surface);
    min-height: 400px;
    transition: grid-template-columns var(--duration-normal) var(--ease-out);
}

.editor-workspace--split {
    grid-template-columns: 1fr 1fr;
}

.editor-workspace--edit {
    grid-template-columns: 1fr;
}

.editor-workspace--edit .add-post-preview {
    display: none;
}

.editor-workspace--preview {
    grid-template-columns: 1fr;
}

.editor-workspace--preview .editor-pane {
    display: none;
}

.editor-pane {
    min-height: 400px;
    border-right: 1px solid var(--color-border);
    position: relative;
}

.editor-workspace--preview .editor-pane,
.editor-workspace--edit .editor-pane {
    border-right: none;
}

.editor-pane .CodeMirror {
    height: 100% !important;
    min-height: 400px;
}

/* CodeMirror */
.add-post-content-section .CodeMirror {
    border: none !important;
    border-radius: 0 !important;
    min-height: 400px;
    font-family: var(--font-mono) !important;
    font-size: 0.875rem;
}

.add-post-content-section .CodeMirror-scroll {
    min-height: 400px;
    max-height: 70vh;
}

.add-post-content-section .CodeMirror-gutters {
    border-right: 1px solid var(--code-border) !important;
    background: var(--code-header-bg) !important;
}

.add-post-content-section .CodeMirror-focused {
    outline: none;
}

/* Превью */
.add-post-preview {
    display: flex;
    flex-direction: column;
    min-height: 400px;
    background: var(--color-bg-subtle);
}

.add-post-preview-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--color-bg);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.add-post-preview-header svg {
    opacity: 0.7;
}

.add-post-preview-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    max-height: 70vh;
    font-family: var(--font-reading);
    font-size: var(--text-reading);
    line-height: var(--line-height-reading);
    letter-spacing: var(--letter-spacing-reading);
    color: var(--color-text);
}

.add-post-preview-body h1,
.add-post-preview-body h2,
.add-post-preview-body h3 {
    color: var(--color-heading);
    margin: 1em 0 0.5em;
    letter-spacing: -0.02em;
}

.add-post-preview-body h1 { font-size: 1.5rem; }
.add-post-preview-body h2 { font-size: 1.25rem; }
.add-post-preview-body h3 { font-size: 1.1rem; }

.add-post-preview-body a {
    color: var(--color-primary);
    text-decoration: none;
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
    transition: border-color var(--duration-fast);
}

.add-post-preview-body a:hover {
    border-bottom-color: var(--color-primary);
}

.add-post-preview-body img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 12px 0;
}

.add-post-preview-body p {
    margin: 0.75em 0;
}

.add-post-preview-body ul,
.add-post-preview-body ol {
    padding-left: 1.5em;
    margin: 0.75em 0;
}

/* Футер формы */
.add-post-footer {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--color-border);
}

.add-post-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-sans);
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}

.add-post-submit:hover {
    background: linear-gradient(135deg, var(--color-primary-hover) 0%, var(--color-primary-dark) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
}

.add-post-submit:active {
    transform: translateY(0);
}

/* Модальное окно шаблонов */
.templates-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn var(--duration-fast) var(--ease-out);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.templates-modal.hidden { display: none; }

.templates-modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
    animation: modalSlideUp var(--duration-normal) var(--ease-out);
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.templates-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
}

.templates-modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    color: var(--color-heading);
}

.close-modal-btn {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--color-text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}

.close-modal-btn:hover {
    background: var(--color-border);
    color: var(--color-heading);
}

.templates-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.template-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    margin-bottom: 10px;
    background: var(--color-bg-subtle);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    transition: border-color var(--duration-fast);
}

.template-item:hover {
    border-color: var(--color-primary);
}

.template-item-name { font-weight: 600; margin-bottom: 4px; }
.template-item-language { font-size: 0.75rem; color: var(--color-text-muted); font-family: var(--font-mono); }
.template-item-actions { display: flex; gap: 8px; }

.btn-small {
    padding: 6px 12px;
    font-size: 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    transition: transform var(--duration-fast);
}

.btn-small:hover { transform: translateY(-1px); }
.btn-edit { background: var(--color-primary); color: white; }
.btn-delete { background: var(--color-danger); color: white; }
.btn-insert { background: var(--color-success); color: white; }

.templates-form {
    border-top: 1px solid var(--color-border);
    padding-top: 24px;
    margin-top: 8px;
}

.templates-form h4 {
    margin-bottom: 16px;
    color: var(--color-heading);
}

.templates-form .form-row {
    margin-bottom: 16px;
}

.templates-form .form-row label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.875rem;
}

.templates-form .form-row input,
.templates-form .form-row select,
.templates-form .form-row textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: var(--font-mono);
}

.templates-form .form-actions {
    display: flex;
    gap: 10px;
}

.templates-form .btn-primary {
    padding: 10px 20px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
}

.templates-form .btn-secondary {
    padding: 10px 20px;
    background: #64748b;
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Попап валидации */
.popup {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.popup.hidden { display: none; }

.popup-content {
    background: var(--color-surface);
    padding: 28px 32px;
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 90%;
    border: 1px solid var(--color-border);
    animation: modalSlideUp var(--duration-normal) var(--ease-out);
}

.close-button {
    margin-top: 16px;
    padding: 10px 24px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    transition: background var(--duration-fast);
}

.close-button:hover {
    background: var(--color-primary-hover);
}

/* Адаптивность */
@media (max-width: 900px) {
    .editor-workspace--split {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .editor-pane {
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
}

@media (max-width: 768px) {
    .add-post-page { padding: 16px 0 32px; }
    .add-post-title { font-size: 1.5rem; }
    .add-post-meta { grid-template-columns: 1fr; }
    .add-post-form { padding: 16px; }
    .editor-view-toggle { width: 100%; }
    .view-mode-btn { flex: 1; text-align: center; padding: 10px 8px; }
    .toolbar-section { flex-direction: column; align-items: stretch; }
    .toolbar-btn, .quick-code-btn { min-height: 44px; }
    .add-post-content-section .CodeMirror-scroll { max-height: 50vh; }
    .add-post-preview-body { max-height: 50vh; }
}

@media (max-width: 480px) {
    .add-post-title { font-size: 1.35rem; }
    .toolbar-btn { flex: 1 1 calc(50% - 4px); justify-content: center; }
    .toolbar-select { width: 100%; }
}
