/* QZAS.CLOUD — минималистичная тема в духе Telegraph/Rentry */

:root {
    --bg: #ffffff;
    --text: #1a1a1a;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #059669;
    --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 17px;
    line-height: 1.65;
}

/* Standalone-режим: только пользовательский контент, центрированный по выбранной ширине. */
.standalone-body {
    padding: 2rem 1rem 3rem;
}

.standalone-body .rendered-content {
    margin: 0 auto;
}


.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
    font-size: 1.15rem;
}

.brand-accent { color: var(--accent); }

.nav-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.95rem;
}

.nav-link:hover { color: var(--accent); }

.container {
    max-width: var(--page-width, 720px);
    margin: 2rem auto;
    padding: 0 1rem;
}

.site-footer {
    max-width: 720px;
    margin: 3rem auto 2rem;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.muted { color: var(--muted); }

h1.page-title { font-size: 1.6rem; margin: 0 0 1rem; }

/* ---------- Редактор ---------- */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.slug-input {
    flex: 1;
    min-width: 200px;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

/* ---------- Выбор ширины страницы ---------- */
.width-picker {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    padding: 0.15rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f8fafc;
}

.width-label {
    font-size: 0.76rem;
    color: var(--muted);
    padding: 0 0.5rem 0 0.4rem;
    user-select: none;
    white-space: nowrap;
}

.width-option {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.width-option:hover { color: var(--accent); }

.width-option.active {
    background: #fff;
    color: var(--accent);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1);
}

/* ---------- Переключатель «чистого вида» ---------- */
.standalone-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--muted);
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    white-space: nowrap;
    user-select: none;
}

.standalone-toggle:hover { color: var(--accent); border-color: var(--accent); }

.standalone-toggle input {
    margin: 0;
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ---------- Табы редактора (в духе rentry) ---------- */
.editor-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1rem;
}

.editor-tab {
    border: none;
    background: transparent;
    padding: 0.55rem 1.1rem;
    font-size: 0.95rem;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px; /* перекрываем границу таб-бара */
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.editor-tab:hover { color: var(--accent); }

.editor-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab-badge {
    display: inline-block;
    min-width: 1.25em;
    padding: 0 0.35em;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.72rem;
    line-height: 1.5;
    text-align: center;
}

.tab-panels { position: relative; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Гибрид: очень широкие экраны — редактор и предпросмотр рядом */
@media (min-width: 1800px) {
    .container { max-width: 1600px; }

    .tab-panels {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
        align-items: start;
    }

    .tab-panel[data-panel="edit"],
    .tab-panel[data-panel="preview"] { display: block !important; }

    .tab-panel[data-panel="files"].active { grid-column: 1 / -1; }

    .editor-tab[data-tab="preview"] { display: none; }

    .content-textarea, .preview-pane, .rich-editor-shell { min-height: 560px; }
}

.content-textarea.editing-hidden { display: none; }

.content-textarea {
    width: 100%;
    max-width: var(--page-width, 720px);
    min-height: 420px;
    resize: vertical;
    padding: 0.9rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92rem;
    line-height: 1.55;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 0 auto;
    display: block;
}

.content-textarea.dragover { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* ---------- Rich text editor ---------- */
.rich-editor-host[hidden] { display: none; }

.rich-editor-shell {
    min-height: 420px;
    max-width: var(--page-width, 720px);
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.rich-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 0.45rem;
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04), 0 6px 16px -8px rgba(15, 23, 42, 0.18);
}

.rich-tool-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
    margin: 0.1rem 0;
    padding: 0.15rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fafafa;
}

.rich-tool,
.rich-block-select {
    flex: 0 0 auto;
    min-height: 2rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #374151;
    font: 600 0.76rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    cursor: pointer;
}

.rich-tool {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.5rem;
    white-space: nowrap;
}
.rich-tool-icon { width: 1.05rem; height: 1.05rem; }
.rich-tool-text { font-weight: 600; }
.rich-block-select { max-width: 8.25rem; padding: 0.3rem 1.6rem 0.3rem 0.45rem; font-weight: 500; }
.rich-tool:hover:not(:disabled), .rich-tool.active { color: var(--accent); background: #fff; border-color: #bfdbfe; }
.rich-tool:focus-visible, .rich-block-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rich-tool:disabled { opacity: 0.35; cursor: not-allowed; }

/* Выпадающее меню таблиц */
.rich-tool-menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    display: none;
    flex-direction: column;
    min-width: 11rem;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    z-index: 20;
}
.rich-tool-menu.open { display: flex; }
.rich-menu-item {
    padding: 0.45rem 0.6rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}
.rich-menu-item:hover:not(:disabled) { background: #eff6ff; color: var(--accent); }
.rich-menu-item:disabled { opacity: 0.35; cursor: not-allowed; }
.rich-menu-insert { border-top: 1px solid var(--border); margin-top: 0.25rem; padding-top: 0.5rem; font-weight: 600; }
.rich-tool-group { position: relative; }

.rich-editor-surface { min-height: 370px; border-radius: 0 0 12px 12px; overflow: hidden; }

.rich-editor-surface .ProseMirror {
    min-height: 370px;
    padding: 1.5rem clamp(1rem, 6vw, 3.25rem) 3rem;
    outline: none;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.05rem;
    line-height: 1.72;
    overflow-wrap: anywhere;
}

.rich-editor-surface .ProseMirror > :first-child { margin-top: 0; }
.rich-editor-surface .ProseMirror p { margin: 0.65em 0; }
.rich-editor-surface .ProseMirror h1,
.rich-editor-surface .ProseMirror h2,
.rich-editor-surface .ProseMirror h3,
.rich-editor-surface .ProseMirror h4 { margin: 1.3em 0 0.45em; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.25; }
.rich-editor-surface .ProseMirror h1 { font-size: 2rem; letter-spacing: -0.025em; }
.rich-editor-surface .ProseMirror h2 { font-size: 1.55rem; }
.rich-editor-surface .ProseMirror h3 { font-size: 1.25rem; }
.rich-editor-surface .ProseMirror a { color: var(--accent); text-decoration: underline; text-underline-offset: 0.15em; }
.rich-editor-surface .ProseMirror blockquote { margin: 1em 0; padding-left: 1rem; border-left: 3px solid #cbd5e1; color: var(--muted); }
.rich-editor-surface .ProseMirror pre { overflow-x: auto; padding: 0.9rem; border-radius: 8px; background: #f6f8fa; font: 0.85rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.rich-editor-surface .ProseMirror :not(pre) > code { border-radius: 4px; background: #f1f5f9; padding: 0.1em 0.3em; font: 0.88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.rich-editor-surface .ProseMirror img { display: block; max-width: 100%; height: auto; margin: 1rem auto; border-radius: 8px; }
.rich-editor-surface .ProseMirror hr { margin: 2rem 0; border: 0; border-top: 2px solid var(--border); }
.rich-editor-surface .ProseMirror-selectednode { outline: 2px solid var(--accent); outline-offset: 2px; }
.rich-editor-surface .ProseMirror ul, .rich-editor-surface .ProseMirror ol { padding-left: 1.7rem; }

.rich-editor-surface .tableWrapper { margin: 1rem 0; overflow-x: auto; }
.rich-editor-surface table { width: 100%; border-collapse: collapse; table-layout: fixed; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 0.9rem; }
.rich-editor-surface td, .rich-editor-surface th { position: relative; min-width: 5rem; padding: 0.45rem 0.6rem; border: 1px solid #cbd5e1; vertical-align: top; }
.rich-editor-surface th { background: #f8fafc; font-weight: 600; }
.rich-editor-surface .selectedCell::after { position: absolute; inset: 0; z-index: 2; content: ""; pointer-events: none; background: rgba(37, 99, 235, 0.12); }
.rich-editor-surface .column-resize-handle { position: absolute; top: 0; right: -2px; bottom: -2px; width: 4px; background: var(--accent); pointer-events: none; }
.resize-cursor { cursor: col-resize; }

@media (max-width: 640px) {
    .editor-tabs { flex-wrap: nowrap; overflow-x: auto; }
    .editor-tab { padding-inline: 0.75rem; }
    .rich-editor-surface .ProseMirror { padding: 1rem 0.9rem 2rem; font-size: 1rem; }
    .content-textarea, .rich-editor-shell, .preview-pane, .rendered-content { max-width: 100%; }
}

.preview-pane {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 0.9rem;
    min-height: 420px;
    max-width: var(--page-width, 720px);
    margin: 0 auto;
    overflow-wrap: break-word;
}

.preview-label, .editor-label {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.editor-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 0.55rem 1.3rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: var(--accent-hover); }

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

.btn-secondary:hover { background: rgba(37, 99, 235, 0.08); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

.upload-zone {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-size: 0.88rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.upload-zone.dragover { outline: 2px dashed var(--accent); outline-offset: -4px; }

.file-list { width: 100%; margin: 0.25rem 0 0; padding: 0; list-style: none; font-size: 0.82rem; }
.file-list li { display: flex; gap: 0.5rem; align-items: center; padding: 0.15rem 0; }
.file-list .file-status-ok { color: var(--success); }
.file-list .file-status-err { color: var(--danger); }

/* ---------- Модальное окно ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal-backdrop.open { display: flex; }

.modal {
    position: relative;
    background: var(--bg);
    border-radius: 12px;
    max-width: 520px;
    width: calc(100% - 2rem);
    padding: 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--accent);
    background: rgba(37, 99, 235, 0.08);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1.25rem;
}

.link-row {
    display: flex;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.link-row input {
    flex: 1;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-family: ui-monospace, monospace;
    color: var(--text);
}

.copy-btn {
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border);
    background: transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
}

.copy-btn:hover { border-color: var(--accent); color: var(--accent); }

.warning-note {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    margin-top: 0.75rem;
}

/* ---------- Приветственное окно с правилами ---------- */
.welcome-modal .modal {
    max-width: 620px;
}

.modal-scroll {
    max-height: 55vh;
    overflow-y: auto;
    margin: 0.5rem 0 0.25rem;
    padding-right: 0.5rem;
    line-height: 1.6;
    font-size: 0.92rem;
}

.modal-scroll > :first-child { margin-top: 0; }
.modal-scroll > :last-child { margin-bottom: 0; }
.modal-scroll h2, .modal-scroll h3, .modal-scroll h4 { margin: 1.1em 0 0.4em; line-height: 1.3; }
.modal-scroll p { margin: 0.6em 0; }
.modal-scroll ul { margin: 0.5em 0; padding-left: 1.4em; }
.modal-scroll li { margin: 0.3em 0; }
.modal-scroll strong { color: var(--text); }
.modal-scroll .muted { font-size: 0.85rem; }


/* ---------- Просмотр страницы ---------- */
/* Общий селектор охватывает и публичную страницу (.rendered-content),
   и предпросмотр в редакторе (.preview-pane). */
.content-area::selection,
.rendered-content ::selection,
.preview-pane ::selection { background: rgba(37, 99, 235, 0.18); }

.rendered-content,
.preview-pane {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Публичная страница: центрированная колонка выбранной ширины с фоном вокруг. */
.rendered-content {
    max-width: var(--page-width, 720px);
    margin: 0 auto;
}

/* Заголовки */
:is(.rendered-content, .preview-pane) h1,
:is(.rendered-content, .preview-pane) h2,
:is(.rendered-content, .preview-pane) h3,
:is(.rendered-content, .preview-pane) h4,
:is(.rendered-content, .preview-pane) h5,
:is(.rendered-content, .preview-pane) h6 {
    margin: 1.5em 0 0.5em;
    line-height: 1.3;
    font-weight: 700;
    scroll-margin-top: 1rem;
}

:is(.rendered-content, .preview-pane) h1:first-child,
:is(.rendered-content, .preview-pane) h2:first-child,
:is(.rendered-content, .preview-pane) h3:first-child,
:is(.rendered-content, .preview-pane) h4:first-child,
:is(.rendered-content, .preview-pane) h5:first-child,
:is(.rendered-content, .preview-pane) h6:first-child { margin-top: 0; }

:is(.rendered-content, .preview-pane) h1 { font-size: 1.75em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
:is(.rendered-content, .preview-pane) h2 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
:is(.rendered-content, .preview-pane) h3 { font-size: 1.2em; }
:is(.rendered-content, .preview-pane) h4 { font-size: 1.05em; }
:is(.rendered-content, .preview-pane) h5 { font-size: 0.95em; }
:is(.rendered-content, .preview-pane) h6 { font-size: 0.85em; color: var(--muted); }

/* Абзацы и списки */
:is(.rendered-content, .preview-pane) p { margin: 0.75em 0; }

:is(.rendered-content, .preview-pane) ul,
:is(.rendered-content, .preview-pane) ol {
    margin: 0.75em 0;
    padding-left: 2em;
}

:is(.rendered-content, .preview-pane) li { margin: 0.25em 0; }

:is(.rendered-content, .preview-pane) li > ul,
:is(.rendered-content, .preview-pane) li > ol { margin: 0.25em 0; }

:is(.rendered-content, .preview-pane) ul.contains-task-list { list-style: none; padding-left: 0.5em; }

/* Ссылки */
:is(.rendered-content, .preview-pane) a {
    color: var(--accent);
    text-decoration: none;
}

:is(.rendered-content, .preview-pane) a:hover { text-decoration: underline; }

/* Горизонтальная линия */
:is(.rendered-content, .preview-pane) hr {
    border: none;
    border-top: 2px solid var(--border);
    margin: 1.5em 0;
}

/* Изображения и видео */
:is(.rendered-content, .preview-pane) img,
:is(.rendered-content, .preview-pane) video {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 0.5em 0;
}

/* Блоки кода */
:is(.rendered-content, .preview-pane) pre {
    background: #f6f8fa;
    padding: 0.9rem;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 1em 0;
}

:is(.rendered-content, .preview-pane) code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:is(.rendered-content, .preview-pane) :not(pre) > code {
    background: #f6f8fa;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1em 0.35em;
    font-size: 0.9em;
}

:is(.rendered-content, .preview-pane) pre > code {
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
}

/* Цитаты */
:is(.rendered-content, .preview-pane) blockquote {
    margin: 1em 0;
    padding: 0.25em 1rem;
    border-left: 4px solid var(--border);
    color: var(--muted);
    background: #fafafa;
    border-radius: 0 var(--radius) var(--radius) 0;
}

:is(.rendered-content, .preview-pane) blockquote > :first-child { margin-top: 0; }
:is(.rendered-content, .preview-pane) blockquote > :last-child { margin-bottom: 0; }

/* Таблицы */
:is(.rendered-content, .preview-pane) table {
    border-collapse: collapse;
    width: 100%;
    max-width: 100%;
    margin: 1em 0;
    font-size: 0.92rem;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

:is(.rendered-content, .preview-pane) thead {
    background: #f6f8fa;
}

:is(.rendered-content, .preview-pane) th,
:is(.rendered-content, .preview-pane) td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.75rem;
    text-align: left;
    vertical-align: top;
    min-width: 5rem;
}

:is(.rendered-content, .preview-pane) th {
    font-weight: 600;
    white-space: nowrap;
}

:is(.rendered-content, .preview-pane) tbody tr:nth-child(even) {
    background: #fafafa;
}

:is(.rendered-content, .preview-pane) tbody tr:hover {
    background: #f1f5f9;
}

.report-bar {
    margin-top: 2.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--muted);
}

.report-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: underline;
}

.report-btn:hover { color: var(--danger); }

.not-found {
    text-align: center;
    padding: 4rem 0;
}

.not-found h1 { font-size: 2rem; }

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
    margin: 0.75rem 0;
    font-size: 0.9rem;
    display: none;
}

.alert-error.visible { display: block; }

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: -2px;
    margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }
