/* GameDB — уютная библиотечная тема */
:root {
    --walnut-deep: #2A1810;
    --walnut: #4A3020;
    --walnut-mid: #6B4A32;
    --walnut-soft: #8B6B4A;
    --beige: #F3EADF;
    --beige-warm: #E8DCC8;
    --beige-dark: #D4C4A8;
    --parchment: #FAF6EF;
    --surface: #FFFCF7;
    --ink: #2C1E12;
    --ink-muted: #5C4636;
    --raspberry: #A31645;
    --raspberry-deep: #7E1235;
    --raspberry-soft: #C94B6E;
    --raspberry-wash: #F3E0E6;
    --raspberry-wash-strong: #E8C8D2;
    --grass: #4F7A4E;
    --grass-deep: #3A5E3A;
    --grass-soft: #6B9A68;
    --border: #D9CBB5;
    --shadow: rgba(42, 24, 16, 0.22);
    --on-accent: #FFFCF7;
    --glass: rgba(255, 252, 247, 0.82);
    --glass-soft: rgba(255, 252, 247, 0.6);
    --grass-tint: rgba(79, 122, 78, 0.14);
    --grass-tint-strong: rgba(79, 122, 78, 0.28);
    --resizer: rgba(212, 196, 168, 0.55);
    --body-bg-color: var(--walnut-deep);
    --body-bg-image:
        radial-gradient(ellipse at 20% 10%, rgba(139, 107, 74, 0.35) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 80%, rgba(74, 48, 32, 0.55) 0%, transparent 45%),
        linear-gradient(160deg, #3D2818 0%, #2A1810 45%, #3A2416 100%);
    --panel-bg: linear-gradient(180deg, var(--surface) 0%, var(--parchment) 100%);
    --content-bg: linear-gradient(180deg, rgba(255, 252, 247, 0.97) 0%, rgba(250, 246, 239, 0.98) 100%);
    --font-display: "Cormorant Garamond", "Times New Roman", serif;
    --font-body: "Literata", "Georgia", serif;
    --font-ui: "Source Sans 3", "Segoe UI", sans-serif;
    color-scheme: light;
}

[data-theme="dark"] {
    --beige: #2A1C14;
    --beige-warm: #332218;
    --beige-dark: #3F2A1C;
    --parchment: #22150F;
    --surface: #1A110C;
    --ink: #F3EADF;
    --ink-muted: #C9B8A0;
    --raspberry: #C94B6E;
    --raspberry-deep: #A31645;
    --raspberry-soft: #E07A96;
    --raspberry-wash: #3A1824;
    --raspberry-wash-strong: #4A1E2E;
    --grass: #6B9A68;
    --grass-deep: #4F7A4E;
    --grass-soft: #8BB888;
    --border: #5C4030;
    --shadow: rgba(0, 0, 0, 0.5);
    --on-accent: #FFFCF7;
    --glass: rgba(42, 24, 16, 0.72);
    --glass-soft: rgba(42, 24, 16, 0.5);
    --grass-tint: rgba(107, 154, 104, 0.18);
    --grass-tint-strong: rgba(107, 154, 104, 0.35);
    --resizer: rgba(139, 107, 74, 0.45);
    --body-bg-color: #120C09;
    --body-bg-image:
        radial-gradient(ellipse at 15% 0%, rgba(107, 74, 50, 0.28) 0%, transparent 48%),
        radial-gradient(ellipse at 85% 100%, rgba(61, 24, 36, 0.35) 0%, transparent 50%),
        linear-gradient(165deg, #1A100C 0%, #120C09 50%, #1E1410 100%);
    --panel-bg: linear-gradient(180deg, #24160F 0%, #1A110C 100%);
    --content-bg: linear-gradient(180deg, #22150F 0%, #1A110C 100%);
    color-scheme: dark;
}

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

body {
    font-family: var(--font-ui);
    background-color: var(--body-bg-color);
    background-image: var(--body-bg-image);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    color: var(--ink);
    overflow-x: hidden;
    overflow-y: auto;
    transition: background-color 0.25s ease, color 0.25s ease;
}

.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 10px;
    box-sizing: border-box;
}

.main-content {
    display: grid;
    grid-template-columns: var(--sidebar-width, 300px) 4px 1fr;
    gap: 10px;
    flex: 1;
    align-items: start;
}

.sidebar {
    background: var(--panel-bg);
    border-radius: 6px;
    padding: 15px;
    box-shadow: 0 8px 28px var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: sticky;
    top: 10px;
    align-self: start;
    max-height: calc(100vh - 20px);
    box-sizing: border-box;
}

.sidebar-resizer {
    grid-column: 2 / 3;
    cursor: col-resize;
    background: linear-gradient(to right, transparent, var(--resizer), transparent);
    border-radius: 6px;
    width: 4px;
    position: sticky;
    top: 10px;
    height: calc(100vh - 20px);
    align-self: start;
}

body.resizing-sidebar {
    cursor: col-resize !important;
    user-select: none;
}

.btn-home {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    background: var(--grass);
    color: var(--on-accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-home:hover {
    background: var(--grass-deep);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(79, 122, 78, 0.4);
}

.btn-home.active {
    background: var(--grass-deep);
}

.btn-templates {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    background: var(--raspberry);
    color: var(--on-accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-templates:hover {
    background: var(--raspberry-deep);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(163, 22, 69, 0.35);
}

.btn-templates.active {
    background: var(--raspberry-deep);
}

.search-box {
    margin-bottom: 20px;
}

.page-tree-container {
    margin-top: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.page-tree-container h3 {
    margin-bottom: 10px;
    font-size: 1.05em;
    color: var(--walnut-mid);
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.page-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.page-tree::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.tree-item {
    margin-bottom: 2px;
}

.tree-node-content {
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 4px;
    padding: 4px 0;
}

.tree-node-content:hover {
    background: var(--beige-warm);
}

.tree-item-active .tree-node-content {
    background: var(--grass-tint);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--grass);
}

.tree-item-active .tree-node-content:hover {
    background: var(--grass-tint-strong);
}

.tree-expand-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 10px;
    color: var(--ink-muted);
    transition: color 0.2s;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.tree-expand-btn:hover {
    color: var(--raspberry);
}

.tree-expand-spacer {
    display: inline-block;
    width: 20px;
    flex-shrink: 0;
}

.tree-link {
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.2s;
    flex: 1;
}

.tree-category-link {
    font-weight: 600;
    color: var(--ink-muted);
    cursor: default;
}

.tree-item-active .tree-link {
    color: var(--grass-deep);
}

.tree-link:hover {
    color: var(--raspberry);
}

.tree-category-link:hover {
    color: var(--ink-muted);
}

.tree-child-count {
    color: var(--walnut-soft);
    font-size: 12px;
    margin-left: auto;
    padding: 4px 8px;
    opacity: 0.7;
    flex-shrink: 0;
}

.tree-category {
    font-weight: 600;
}

.tree-empty {
    padding: 20px;
    text-align: center;
    color: var(--walnut-soft);
    font-style: italic;
    font-size: 14px;
}

.search-box input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: var(--font-ui);
    background: var(--parchment);
    color: var(--ink);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--grass);
    box-shadow: 0 0 0 3px rgba(79, 122, 78, 0.2);
}

.category-filter {
    margin-bottom: 20px;
}

.category-filter h3 {
    margin-bottom: 10px;
    font-size: 1.1em;
    color: var(--ink-muted);
}

.category-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 5px;
    border: none;
    background: var(--beige);
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    transition: all 0.3s;
    font-size: 14px;
}

.category-btn:hover {
    background: var(--beige-dark);
    transform: translateX(5px);
}

.category-btn.active {
    background: var(--raspberry);
    color: var(--on-accent);
}

.page-list-container h3 {
    margin-bottom: 10px;
    font-size: 1.1em;
    color: var(--ink-muted);
}

.page-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    margin-bottom: 15px;
    min-height: 0;
}

.page-list li {
    padding: 8px 12px;
    margin-bottom: 5px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
}

.page-list li:hover {
    background: var(--beige-warm);
    transform: translateX(5px);
}

.page-list li.empty {
    color: var(--walnut-soft);
    font-style: italic;
    cursor: default;
}

.page-list li.empty:hover {
    background: transparent;
    transform: none;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-family: var(--font-ui);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary {
    background: var(--raspberry);
    color: var(--on-accent);
}

.btn-primary:hover {
    background: var(--raspberry-deep);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(163, 22, 69, 0.35);
}

.btn-secondary {
    background: var(--walnut);
    color: var(--on-accent);
}

.btn-secondary:hover {
    background: var(--walnut);
}

.btn-danger {
    background: var(--raspberry);
    color: var(--on-accent);
}

.btn-danger:hover {
    background: var(--raspberry-deep);
}

#newPageBtn {
    width: 100%;
    margin-top: 10px;
}

.content-area {
    background: var(--content-bg);
    border-radius: 6px;
    padding: 20px;
    box-shadow: 0 8px 28px var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 10px;
    height: calc(100vh - 20px);
    max-height: calc(100vh - 20px);
    min-height: 0;
    box-sizing: border-box;
}

.welcome-screen {
    text-align: center;
    padding: 50px 20px;
    color: var(--ink-muted);
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.welcome-screen h2 {
    margin-bottom: 15px;
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 2.2em;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.page-viewer {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.page-viewer .page-header {
    position: relative;
    z-index: 5;
    border-bottom: 2px solid var(--border);
    padding-top: 4px;
    padding-bottom: 15px;
    margin-bottom: 12px;
    flex-shrink: 0;
    background: var(--content-bg);
}

.page-viewer .page-content {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.page-viewer .page-content::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.page-header-path {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
    min-width: 0;
}

.page-header-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 0;
    min-width: 0;
}

.page-viewer .page-header-title {
    margin-bottom: 0;
}

.editor-page-header .page-header-title {
    margin-bottom: 10px;
}

.breadcrumbs {
    margin-bottom: 0;
    font-size: 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    color: var(--ink-muted);
    min-width: 0;
    flex: 1;
}

.page-header-aside {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-left: auto;
}

.page-backlinks-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--glass-soft);
    color: var(--ink-muted);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.page-backlinks-btn:hover {
    background: var(--raspberry-wash);
    border-color: var(--raspberry-soft);
    color: var(--raspberry-deep);
}

.page-backlinks-btn.active {
    background: var(--raspberry);
    border-color: var(--raspberry);
    color: var(--on-accent);
}

.page-updated {
    flex-shrink: 0;
    text-align: right;
    font-size: 13px;
    color: var(--ink-muted);
    opacity: 0.55;
    white-space: nowrap;
}

.page-edit-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--glass-soft);
    color: var(--ink-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.page-edit-btn:hover {
    background: var(--raspberry-wash);
    border-color: var(--raspberry-soft);
    color: var(--raspberry-deep);
}

.page-edit-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(163, 22, 69, 0.22);
}

.page-edit-icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: block;
}

.page-edit-btn[hidden],
#deleteBtn[hidden] {
    display: none !important;
}

@media (max-width: 640px) {
    .page-header-path,
    .page-header-title {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .page-header-aside,
    .page-header-title .page-type-badge {
        margin-left: 0;
        width: 100%;
    }

    .page-header-aside {
        justify-content: flex-start;
    }

    .page-updated {
        text-align: left;
    }
}

.breadcrumb-item {
    display: inline-block;
    transition: all 0.3s;
}

.breadcrumb-link {
    color: var(--raspberry);
    text-decoration: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
}

.breadcrumb-link:hover {
    background: var(--raspberry);
    color: var(--on-accent);
}

.breadcrumb-current {
    color: var(--ink);
    font-weight: 600;
}

.breadcrumb-separator {
    margin: 0 5px;
    color: var(--walnut-soft);
    user-select: none;
}

.page-header-title h2,
.page-header h2 {
    margin-bottom: 0;
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 2em;
    font-weight: 600;
    letter-spacing: 0.01em;
    min-width: 0;
    flex: 1;
}

.page-header-title .page-type-badge {
    flex-shrink: 0;
    margin-left: auto;
    align-self: center;
}

.page-type-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 4px;
    background: var(--grass-tint);
    color: var(--grass-deep);
    border: 1px solid var(--grass-tint-strong);
    font-family: var(--font-ui);
    font-size: 0.85em;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

[data-theme="dark"] .page-type-badge {
    color: var(--grass-soft);
}

.category-badge {
    padding: 4px 12px;
    background: var(--raspberry);
    color: var(--on-accent);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

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

.editor-page-header {
    position: relative;
    z-index: 5;
    border-bottom: 2px solid var(--border);
    padding-top: 4px;
    padding-bottom: 15px;
    margin-bottom: 12px;
    flex-shrink: 0;
    background: var(--content-bg);
}

.page-editor .editor-body {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.page-editor .editor-body::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.editor-page-header .page-header-path {
    align-items: center;
    gap: 12px;
}

.editor-page-header .page-actions {
    flex-shrink: 0;
    margin-left: auto;
    align-items: center;
}

.editor-page-header .page-actions .btn {
    padding: 8px 14px;
}

.editor-parent-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.editor-parent-row label {
    flex-shrink: 0;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-muted);
    white-space: nowrap;
}

.parent-picker {
    position: relative;
    flex: 1;
    min-width: 0;
    max-width: 420px;
}

.parent-picker-control {
    position: relative;
    display: flex;
    align-items: center;
}

.parent-picker-input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 32px 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 14px;
}

.parent-picker-input:focus {
    outline: none;
    border-color: var(--grass);
    box-shadow: 0 0 0 3px rgba(79, 122, 78, 0.15);
}

.parent-picker-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--ink-muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.parent-picker-clear:hover {
    background: var(--raspberry-wash);
    color: var(--raspberry-deep);
}

.parent-picker-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 30;
    max-height: 260px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 10px 28px var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.parent-picker-suggestions[hidden] {
    display: none !important;
}

.parent-picker-item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.parent-picker-item:hover {
    background: var(--raspberry-wash);
    color: var(--ink);
}

.parent-picker-item.is-active {
    background: var(--raspberry);
    color: var(--on-accent);
}

.parent-picker-empty {
    padding: 10px;
    color: var(--ink-muted);
    font-size: 13px;
    text-align: center;
}

.edit-title-input {
    flex: 1;
    min-width: 0;
    width: auto;
    margin: 0;
    padding: 0;
    border: none;
    border-bottom: 1px dashed transparent;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 2em;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.2;
}

.edit-title-input:focus {
    outline: none;
    border-bottom-color: var(--grass);
    box-shadow: none;
    background: transparent;
}

.edit-title-input::placeholder {
    color: var(--walnut-soft);
    opacity: 0.7;
    font-weight: 500;
}

.type-picker {
    position: relative;
    flex-shrink: 0;
    margin-left: auto;
    align-self: center;
    max-width: 240px;
}

.type-picker-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 240px;
    padding: 4px 28px 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background-color: var(--surface);
    background-image:
        linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%),
        linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%);
    background-position:
        calc(100% - 12px) 55%,
        calc(100% - 7px) 55%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s, color 0.2s;
}

.type-picker-btn > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.type-picker-btn:hover {
    border-color: var(--raspberry-soft);
    background-color: var(--raspberry-wash);
    color: var(--raspberry-deep);
    background-image:
        linear-gradient(45deg, transparent 50%, var(--raspberry-deep) 50%),
        linear-gradient(135deg, var(--raspberry-deep) 50%, transparent 50%);
}

.type-picker-btn:focus-visible,
.type-picker-btn[aria-expanded="true"] {
    outline: none;
    border-color: var(--grass);
    box-shadow: 0 0 0 3px var(--grass-tint);
}

.type-picker-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 40;
    min-width: 100%;
    width: max-content;
    max-width: min(320px, 70vw);
    max-height: 280px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 10px 28px var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.type-picker-menu[hidden] {
    display: none !important;
}

.type-picker-item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.type-picker-item:hover {
    background: var(--raspberry-wash);
    color: var(--ink);
}

.type-picker-item.is-active {
    background: var(--raspberry);
    color: var(--on-accent);
}

.editor-body {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

@media (max-width: 640px) {
    .editor-parent-row {
        flex-wrap: wrap;
    }

    .editor-parent-row select {
        max-width: none;
        width: 100%;
    }

    .type-picker {
        margin-left: 0;
        max-width: none;
        width: 100%;
    }

    .type-picker-btn {
        width: 100%;
        max-width: none;
    }
}

.page-content {
    font-family: var(--font-body);
    line-height: 1.75;
    font-size: 1.05em;
    color: var(--ink);
    overflow: visible;
}

/* ==================== PAGE v2 (обложка + текст + галерея) ==================== */

.page-v2 {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.page-v2-main {
    display: block;
    min-width: 0;
    width: 100%;
}

.page-v2-covers {
    /* По умолчанию дети участвуют в раскладке родителя (персонаж/обычная страница) */
    display: contents;
}

.page-v2-emblem,
.page-v2-cover {
    /* Область картинки; обводка через shadow, чтобы не съедать пропорцию */
    position: relative;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 4 / 1;
    height: auto;
    margin: 0 0 14px;
    box-sizing: border-box;
    overflow: hidden;
    border-radius: 4px;
    border: none;
    background: var(--beige);
    box-shadow: 0 0 0 1px var(--border), 0 4px 14px var(--shadow);
}

.page-v2-emblem {
    aspect-ratio: 1 / 1;
}

.page-v2-emblem[hidden],
.page-v2-cover[hidden] {
    display: none !important;
}

/* Организация: эмблема 1:1 + обложка 3:1 одинаковой высоты */
.page-v2.is-organization-layout .page-v2-covers {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    margin: 0 0 14px;
    align-items: stretch;
}

.page-v2.is-organization-layout:not(.has-cover) .page-v2-covers {
    display: none;
}

.page-v2.is-organization-layout.has-emblem.has-banner .page-v2-covers {
    grid-template-columns: 1fr 3fr;
}

.page-v2.is-organization-layout.has-emblem:not(.has-banner) .page-v2-emblem {
    width: min(25%, 220px);
}

.page-v2.is-organization-layout .page-v2-emblem,
.page-v2.is-organization-layout .page-v2-cover {
    margin: 0;
    width: 100%;
    max-width: none;
    height: auto;
}

.page-v2.is-organization-layout .page-v2-emblem {
    aspect-ratio: 1 / 1;
}

.page-v2.is-organization-layout .page-v2-cover {
    aspect-ratio: 3 / 1;
}

.page-v2-meta {
    width: 100%;
    max-width: 100%;
    margin: 0 0 14px;
    overflow-x: auto;
}

/* Страница персонажа: портрет 1:2 слева (sticky) + атрибуты/текст справа */
.page-v2.is-character-layout {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    /* auto + 1fr: высота портрета не раздувает ряд с атрибутами,
       текст остаётся сразу под мета-таблицей */
    grid-template-rows: auto 1fr;
    column-gap: 20px;
    row-gap: 14px;
    align-items: start;
}

.page-v2.is-character-layout .page-v2-cover {
    grid-column: 1;
    grid-row: 1 / span 2;
    position: sticky;
    top: var(--character-cover-top, 0px);
    z-index: 2;
    width: var(--character-cover-w, calc(var(--character-cover-h, 50vh) / 2));
    height: var(--character-cover-h, 50vh);
    max-width: none;
    max-height: var(--character-cover-h, 50vh);
    aspect-ratio: auto;
    margin: 0;
    align-self: start;
}

.page-v2.is-character-layout .page-v2-meta {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
    min-width: 0;
}

.page-v2.is-character-layout .page-v2-main {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
}

.page-v2.is-character-layout:not(.has-meta) .page-v2-main {
    grid-row: 1 / span 2;
}

.meta-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--beige);
    font-size: 14px;
}

.meta-table td {
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    vertical-align: top;
    overflow-wrap: break-word;
    word-break: normal;
}

.meta-table tr:first-child td {
    border-top: none;
}

.meta-table-horizontal {
    min-width: 100%;
}

.meta-table-horizontal td {
    width: auto;
    min-width: 140px;
}

.meta-table-horizontal tr.meta-view-names td,
.meta-table-horizontal td.meta-field-name {
    font-weight: 600;
    color: var(--ink);
    background: rgba(0, 0, 0, 0.03);
}

.meta-table-horizontal td.meta-field-value {
    color: var(--ink-muted);
}

.page-v2-cover-img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    border: none;
    border-radius: 0;
    object-fit: contain;
    object-position: center center;
    background: transparent;
    box-shadow: none;
}

.page-v2-cover-img[hidden] {
    display: none !important;
}

.page-v2-text {
    min-height: 50px;
    overflow-wrap: anywhere;
}

.page-v2-gallery {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    background: var(--glass);
}

.gallery-nav {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: var(--surface);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.gallery-nav:disabled {
    opacity: 0.4;
    cursor: default;
}

.gallery-strip {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    min-width: 0;
}

.gallery-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.gallery-img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--beige);
}

.gallery-caption {
    font-size: 12px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.page-blocks {
    display: block;
    min-width: 0;
}

.page-blocks > .content-block + .content-block {
    margin-top: 18px;
}

.content-block-text {
    text-align: justify;
    overflow-wrap: break-word;
}

.content-block-text > p,
.edit-block-rich-text > p,
.edit-block-rich-text > div {
    margin: 0 0 0.85em;
    text-indent: 1.5em;
}

.content-block-text > p:last-child,
.edit-block-rich-text > p:last-child,
.edit-block-rich-text > div:last-child {
    margin-bottom: 0;
}

.content-block-image-text {
    display: block;
}

.content-block-image-text::after {
    content: '';
    display: table;
    clear: both;
}

.content-block-float-img {
    float: left;
    width: 220px;
    max-width: 45%;
    height: auto;
    margin: 0 16px 10px 0;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--beige);
}

.content-block-image-text .content-block-text {
    text-align: justify;
    overflow-wrap: break-word;
}

.content-block-gallery {
    clear: both;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    background: var(--glass);
}

.content-block-gallery.is-carousel {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
}

.gallery-carousel-stage {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.gallery-carousel-img {
    display: block;
    width: 100%;
    max-height: min(56vh, 520px);
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--beige);
}

.gallery-carousel-caption {
    max-width: 100%;
    white-space: normal;
    text-align: center;
}

.gallery-carousel-counter {
    font-size: 12px;
    color: var(--ink-muted);
    letter-spacing: 0.04em;
}

.gallery-carousel-empty {
    width: 100%;
    text-align: center;
    color: var(--ink-muted);
    padding: 28px 12px;
}

.content-block-gallery.is-carousel .gallery-nav {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.content-block-gallery.is-carousel .gallery-nav:hover:not(:disabled) {
    background: var(--beige-warm);
}

.content-block-gallery.is-carousel .gallery-nav:disabled {
    opacity: 0.35;
    cursor: default;
}

.content-block-prompt-text {
    position: relative;
    clear: both;
    padding: 14px 16px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    background: var(--glass);
}

.prompt-copy-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    padding: 6px 10px;
    font-size: 12px;
}

.prompt-copy-btn.is-copied {
    background: var(--grass);
    color: var(--on-accent);
    border-color: var(--grass);
}

.prompt-text-body {
    font-family: var(--font-body);
    font-size: 0.98em;
    line-height: 1.25;
    color: var(--ink);
    padding-right: 110px;
    overflow-wrap: break-word;
}

.prompt-text-body > p {
    margin: 0 0 0.2em;
    text-indent: 0;
    text-align: left;
    line-height: 1.25;
}

.prompt-text-body > p:last-child {
    margin-bottom: 0;
}

.prompt-text-body.is-empty {
    color: var(--ink-muted);
    white-space: normal;
}

.prompt-editor-label {
    margin: 4px 0 6px;
    font-family: var(--font-display);
    font-size: 0.95em;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--walnut-mid);
}

.edit-block-shell.content-block-prompt-text {
    padding-top: 12px;
}

.edit-prompt-text,
.edit-prompt-text.edit-block-rich-text {
    line-height: 1.25;
    text-align: left;
}

.edit-prompt-text > p,
.edit-prompt-text > div {
    margin: 0 0 0.2em;
    text-indent: 0;
    line-height: 1.25;
}

.edit-prompt-text > p:last-child,
.edit-prompt-text > div:last-child {
    margin-bottom: 0;
}

.blocks-toolbar[hidden] {
    display: none !important;
}

/* Страница промпта: без заглавного фото */
.page-v2.is-prompt-layout .page-v2-covers,
.editor-v2.is-prompt-layout .editor-v2-covers,
.editor-v2-covers[hidden] {
    display: none !important;
}

.blocks-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.blocks-toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.edit-blocks {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.edit-blocks-empty {
    padding: 18px;
    border: 1px dashed var(--shadow);
    border-radius: 10px;
    color: var(--ink-muted);
    background: var(--glass-soft);
}

.edit-block-shell {
    position: relative;
    padding-top: 36px;
}

.edit-block-shell:hover,
.edit-block-shell:focus-within {
    outline: 1px dashed var(--border);
    outline-offset: 6px;
    border-radius: 4px;
}

.edit-block-controls {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    z-index: 3;
}

.edit-block-ctrl-btn {
    padding: 4px 10px !important;
    font-size: 12px !important;
    border-radius: 4px !important;
    transform: none !important;
    box-shadow: none !important;
}

.edit-block-text-input {
    width: 100%;
    box-sizing: border-box;
    resize: none;
    overflow: hidden;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 1.05em;
    line-height: 1.75;
    text-align: justify;
}

.edit-block-text-input:focus {
    outline: none;
    box-shadow: none;
    background: transparent;
}

.edit-block-text-input::placeholder {
    color: var(--walnut-soft);
    opacity: 0.75;
    text-align: left;
}

.edit-float-media {
    float: left;
    width: 220px;
    max-width: 45%;
    margin: 0 16px 10px 0;
}

.edit-float-media .content-block-float-img {
    float: none;
    width: 100%;
    max-width: none;
    margin: 0 0 6px;
}

.edit-float-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    color: var(--ink-muted);
    font-size: 13px;
    text-align: center;
    background: var(--beige);
}

.edit-inline-media-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.edit-gallery-item {
    position: relative;
}

.edit-gallery-item .edit-gallery-caption-input {
    width: 100%;
    box-sizing: border-box;
    border: none;
    border-bottom: 1px dashed var(--border);
    border-radius: 0;
    background: transparent;
    padding: 2px 0;
    font-size: 12px;
    text-align: center;
    color: var(--ink-muted);
}

.edit-gallery-item .edit-gallery-caption-input:focus {
    outline: none;
    border-bottom-color: var(--grass);
}

.edit-gallery-item-actions {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 4px;
}

.edit-gallery-add-btn {
    margin-top: 10px;
}

/* ==================== EDITOR v2 ==================== */

.editor-v2 {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
}

.editor-v2-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    min-width: 0;
}

.editor-v2-covers {
    display: contents;
}

.editor-v2-emblem,
.editor-v2-cover {
    width: 100%;
    max-width: 100%;
}

.editor-v2-cover-preview {
    /* Та же область 4:1, что в просмотре */
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 4 / 1;
    height: auto;
    box-sizing: border-box;
    overflow: hidden;
    cursor: pointer;
    border-radius: 4px;
    border: none;
    background: var(--beige);
    box-shadow: 0 0 0 1px var(--border), 0 4px 14px var(--shadow);
}

.editor-v2-cover-preview.is-emblem {
    aspect-ratio: 1 / 1;
}

.editor-v2.is-organization-layout .editor-v2-covers {
    display: grid;
    grid-template-columns: 1fr 3fr;
    gap: 12px;
    width: 100%;
    align-items: stretch;
}

.editor-v2.is-organization-layout .editor-v2-emblem,
.editor-v2.is-organization-layout .editor-v2-cover {
    width: 100%;
    max-width: none;
    min-width: 0;
}

.editor-v2.is-organization-layout .editor-v2-cover-preview {
    aspect-ratio: 3 / 1;
}

.editor-v2.is-organization-layout .editor-v2-cover-preview.is-emblem {
    aspect-ratio: 1 / 1;
}

.editor-v2.is-character-layout {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    /* auto + 1fr: высота портрета не раздувает ряд с атрибутами,
       текст остаётся сразу под мета-таблицей */
    grid-template-rows: auto 1fr;
    column-gap: 20px;
    row-gap: 14px;
    align-items: start;
}

.editor-v2.is-character-layout .editor-v2-cover {
    grid-column: 1;
    grid-row: 1 / span 2;
    position: sticky;
    top: var(--character-cover-top, 0px);
    z-index: 2;
    width: var(--character-cover-w, calc(var(--character-cover-h, 50vh) / 2));
    max-width: none;
    align-self: start;
}

.editor-v2.is-character-layout .editor-v2-cover-preview {
    width: 100%;
    height: var(--character-cover-h, 50vh);
    max-height: var(--character-cover-h, 50vh);
    aspect-ratio: auto;
}

.editor-v2.is-character-layout .editor-v2-meta {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
    min-width: 0;
}

.editor-v2.is-character-layout .editor-v2-body {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
}

.editor-v2.is-character-layout:not(.has-meta) .editor-v2-body {
    grid-row: 1 / span 2;
}

.editor-v2-cover-preview:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 122, 78, 0.28);
}

.editor-v2-cover-preview .page-v2-cover-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    display: block;
    pointer-events: none;
    object-fit: contain;
    object-position: center center;
}

.editor-v2-cover-preview .page-v2-cover-img[hidden],
.cover-placeholder[hidden] {
    display: none !important;
}

.cover-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 18px;
    border: 1px dashed var(--shadow);
    border-radius: 4px;
    color: var(--ink-muted);
    background: var(--glass-soft);
    width: auto;
    height: auto;
    box-sizing: border-box;
    min-height: 0;
    pointer-events: none;
}

.editor-v2-text textarea {
    width: 100%;
    resize: vertical;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    font-family: inherit;
    line-height: 1.5;
}

.editor-v2-gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.editor-v2-meta {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.editor-v2-meta-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.meta-rows-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.meta-rows-controls input[type="number"] {
    width: 80px;
    padding: 6px 8px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.meta-table-edit {
    table-layout: fixed;
    width: 100%;
    overflow: visible;
}

.editor-v2-meta .meta-table-edit {
    width: 100%;
}

.editor-v2-meta .meta-table-edit-horizontal {
    min-width: 100%;
}

.editor-v2-meta .meta-table-edit-horizontal td {
    width: auto;
    min-width: 140px;
    vertical-align: top;
}

.editor-v2-meta .meta-table-edit-horizontal tr.meta-edit-names td {
    font-weight: 600;
    color: var(--ink);
    background: rgba(0, 0, 0, 0.03);
}

/* Align viewer/editor horizontal meta header cells */
.meta-table-horizontal tr.meta-view-names td + td,
.meta-table-edit-horizontal tr.meta-edit-names td + td {
    border-left: 1px solid var(--border);
}

.meta-table-horizontal tr.meta-view-values td + td,
.meta-table-edit-horizontal tr.meta-edit-values td + td {
    border-left: 1px solid var(--border);
}

.editor-v2-meta .meta-table-edit td.meta-field-name {
    font-weight: 600;
    color: var(--ink);
    overflow-wrap: break-word;
    word-break: normal;
}

.editor-v2-meta .meta-table-edit td.meta-field-value {
    color: var(--ink-muted);
    overflow-wrap: break-word;
    word-break: normal;
}

.editor-v2-meta .meta-table-edit textarea.meta-field-name-input {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    field-sizing: content;
}

.editor-v2-meta .meta-table-edit textarea.meta-field-name-input:focus {
    outline: none;
    box-shadow: inset 0 -1px 0 var(--grass);
}

.editor-v2-meta .meta-table-edit textarea.meta-field-name-input::placeholder {
    font-weight: 400;
    color: var(--walnut-soft);
    opacity: 0.8;
}

.editor-v2-meta .meta-table-edit input[type="text"] {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
}

.meta-table td.relation-view {
    /* на случай старой разметки: не даём flex сломать table-cell */
    display: table-cell;
}

.relation-view {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: break-word;
    word-break: normal;
}

.relation-view-item {
    display: block;
    width: 100%;
    box-sizing: border-box;
    overflow-wrap: break-word;
    word-break: normal;
    line-height: 1.45;
}

.relation-view-item a {
    color: var(--raspberry);
    text-decoration: none;
    transition: color 0.2s;
}

.relation-view-item a:hover {
    color: var(--raspberry-soft);
}

.relation-view-note {
    color: var(--ink-muted);
}

.meta-field-relations {
    overflow: visible;
}

.relation-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.relation-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.relation-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 6px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--beige);
}

.relation-item-title {
    font-weight: 600;
    color: var(--ink);
    overflow-wrap: anywhere;
    flex: 1 1 auto;
    min-width: 0;
}

.relation-note-wrap {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: var(--ink-muted);
    font-size: 13px;
    flex: 1 1 100%;
}

.relation-note-input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    border: none !important;
    border-bottom: 1px dashed var(--border) !important;
    border-radius: 0 !important;
    background: transparent !important;
    padding: 2px 0 !important;
    font-size: 13px;
    color: var(--ink-muted);
}

.relation-note-input:focus {
    outline: none;
    border-bottom-color: var(--grass) !important;
}

.relation-remove {
    margin-left: auto;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 4px;
    background: var(--raspberry);
    color: var(--on-accent);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

.relation-remove:hover {
    background: var(--raspberry-deep);
}

.relation-search {
    position: relative;
}

.relation-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
}

.relation-search-input:focus {
    outline: none;
    border-color: var(--grass);
    box-shadow: 0 0 0 3px rgba(79, 122, 78, 0.15);
}

.relation-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 20;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: 0 8px 20px var(--shadow);
}

.relation-suggestion {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
}

.relation-suggestion:hover,
.relation-suggestion:focus {
    background: var(--grass-tint);
    outline: none;
}

.relation-suggestion-empty {
    padding: 8px 10px;
    color: var(--ink-muted);
    font-size: 13px;
    font-style: italic;
}

.meta-table-edit td.meta-row-delete-cell {
    width: 0;
    padding: 0;
    border: none;
    background: transparent;
    position: relative;
    overflow: visible;
}

.meta-row-delete {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: var(--raspberry);
    color: var(--on-accent);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    z-index: 2;
}

.meta-row-delete:hover {
    background: var(--raspberry-deep);
}

#addTemplateMetaRowBtn {
    width: 220px;
    margin-top: 8px;
    box-sizing: border-box;
}

.template-fields-editor {
    margin-bottom: 20px;
}

.template-fields-table {
    width: 100%;
    max-width: 480px;
}

.template-fields-editor .meta-table-edit {
    width: 100%;
    max-width: 480px;
}

.template-fields-editor .meta-table-edit td:first-child {
    width: auto;
}

.template-fields-editor #addTemplateMetaRowBtn {
    width: auto;
    min-width: 160px;
}

.meta-table-edit:empty {
    display: none;
}

.edit-gallery-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.edit-gallery-row {
    display: grid;
    grid-template-columns: 70px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    background: var(--glass);
}

.edit-gallery-thumb {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--beige);
}

.edit-gallery-caption-input {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
}

.edit-gallery-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 900px) {
    .page-v2-meta {
        width: 100%;
        max-width: 100%;
    }
    .page-v2-emblem,
    .page-v2-cover {
        width: 100%;
        max-width: 100%;
    }

    .page-v2.is-organization-layout .page-v2-covers,
    .editor-v2.is-organization-layout .editor-v2-covers {
        grid-template-columns: 1fr;
    }

    .page-v2.is-organization-layout .page-v2-emblem,
    .editor-v2.is-organization-layout .editor-v2-emblem {
        width: min(220px, 55vw);
        justify-self: start;
    }

    .page-v2.is-character-layout,
    .editor-v2.is-character-layout {
        display: flex;
        flex-direction: column;
    }

    .page-v2.is-character-layout .page-v2-cover,
    .editor-v2.is-character-layout .editor-v2-cover {
        position: relative;
        top: auto;
        width: min(280px, 70vw);
        height: auto;
        aspect-ratio: 1 / 2;
        --character-cover-h: auto;
        align-self: center;
    }

    .page-v2.is-character-layout .page-v2-cover {
        height: auto;
        aspect-ratio: 1 / 2;
    }

    .editor-v2.is-character-layout .editor-v2-cover-preview {
        height: auto;
        aspect-ratio: 1 / 2;
    }

    .page-v2.is-character-layout .page-v2-meta,
    .page-v2.is-character-layout .page-v2-main,
    .page-v2.is-character-layout:not(.has-meta) .page-v2-main,
    .editor-v2.is-character-layout .editor-v2-meta,
    .editor-v2.is-character-layout .editor-v2-body,
    .editor-v2.is-character-layout:not(.has-meta) .editor-v2-body {
        grid-column: auto;
        grid-row: auto;
    }
    .gallery-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .editor-page-header .page-header-path {
        flex-wrap: wrap;
    }

    .editor-page-header .page-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .content-block-float-img {
        max-width: 40%;
        width: 160px;
    }
    .edit-image-text {
        grid-template-columns: 1fr;
    }
}

.page-content p {
    margin-bottom: 15px;
}

.page-v2-meta,
.meta-table {
    font-family: var(--font-ui);
}

.page-content a,
.edit-block-rich-text .wiki-link {
    color: var(--raspberry);
    text-decoration: none;
    border-bottom: none;
    background: transparent;
    padding: 0;
    border-radius: 0;
    transition: color 0.2s;
}

.page-content a:hover,
.edit-block-rich-text .wiki-link:hover {
    background: transparent;
    color: var(--raspberry-soft);
}

.page-content .wiki-link-missing {
    color: var(--ink-muted);
    border-bottom: none;
}

.edit-block-rich-text {
    min-height: 72px;
    height: auto;
    overflow-wrap: anywhere;
    word-break: break-word;
    cursor: text;
}

.edit-block-shell.content-block-text,
.edit-block-shell.content-block-heading-text {
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.edit-block-rich-text.is-empty::before {
    content: attr(data-placeholder);
    color: var(--walnut-soft);
    opacity: 0.75;
    pointer-events: none;
    float: left;
    height: 0;
}

.edit-block-rich-text .wiki-link {
    cursor: text;
}

.wiki-link-menu,
.wiki-link-picker {
    position: fixed;
    z-index: 4000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 28px var(--shadow);
    font-family: var(--font-ui);
}

.wiki-link-menu {
    padding: 4px;
}

.wiki-link-menu-btn {
    display: block;
    width: 100%;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.wiki-link-menu-btn:hover {
    background: var(--raspberry-wash);
    color: var(--ink);
}

.wiki-link-picker {
    width: min(420px, calc(100vw - 24px));
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wiki-link-picker[hidden],
.wiki-link-menu[hidden] {
    display: none !important;
}

.wiki-link-picker-search {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--parchment);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}

.wiki-link-picker-search:focus {
    outline: none;
    border-color: var(--grass);
    box-shadow: 0 0 0 2px var(--grass-tint);
}

.wiki-link-picker-list {
    max-height: 280px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.wiki-link-picker-item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.wiki-link-picker-item:hover {
    background: var(--raspberry-wash);
    color: var(--ink);
}

.wiki-link-picker-item.is-active {
    background: var(--raspberry);
    color: var(--on-accent);
}

.wiki-link-picker-empty {
    padding: 10px;
    color: var(--ink-muted);
    font-size: 13px;
    text-align: center;
}

.page-editor {
    animation: fadeIn 0.3s;
}

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

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--ink-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--ink);
    transition: border-color 0.3s, box-shadow 0.3s, background 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--grass);
    box-shadow: 0 0 0 3px rgba(79, 122, 78, 0.15);
    background: var(--surface);
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: var(--walnut-soft);
    font-size: 12px;
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 30px;
}

/* Скроллбар */
.page-list::-webkit-scrollbar,
textarea::-webkit-scrollbar {
    width: 8px;
}

.page-list::-webkit-scrollbar-track,
textarea::-webkit-scrollbar-track {
    background: var(--beige-warm);
    border-radius: 10px;
}

.page-list::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb {
    background: var(--walnut-soft);
    border-radius: 10px;
}

.page-list::-webkit-scrollbar-thumb:hover,
textarea::-webkit-scrollbar-thumb:hover {
    background: var(--ink-muted);
}

.categories-screen {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.categories-screen h2 {
    margin-bottom: 20px;
    color: var(--ink);
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    flex: 1;
    overflow-y: auto;
}

.category-card {
    background: linear-gradient(135deg, var(--walnut-mid) 0%, var(--walnut-deep) 100%);
    border-radius: 10px;
    padding: 25px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    color: var(--on-accent);
    box-shadow: 0 5px 15px var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 150px;
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(42, 24, 16, 0.32);
}

.category-card h3 {
    font-size: 1.5em;
    margin-bottom: 10px;
}

.category-card .count {
    font-size: 0.9em;
    opacity: 0.9;
}

.category-pages-screen {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border);
    flex-shrink: 0;
}

.category-header h2 {
    color: var(--ink);
    margin: 0;
}

.alphabetical-list,
.alpha-index {
    width: 100%;
    min-width: 0;
}

.alpha-index-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 6px;
    align-items: center;
    margin: 4px 0 28px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.4;
}

.alpha-index-nav a {
    color: var(--raspberry);
    text-decoration: none;
    padding: 0;
    transition: color 0.2s;
}

.alpha-index-nav a:hover {
    color: var(--raspberry-soft);
    background: transparent;
}

.alpha-index-nav-empty {
    color: var(--ink-muted);
    opacity: 0.4;
    user-select: none;
}

.alpha-index-empty {
    color: var(--ink-muted);
    font-family: var(--font-ui);
    padding: 8px 0;
}

.letter-section {
    margin-bottom: 28px;
}

.letter-header {
    font-family: var(--font-display);
    font-size: 1.7em;
    font-weight: 600;
    color: var(--raspberry);
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    scroll-margin-top: 16px;
}

.letter-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px 18px;
}

.page-link-item {
    padding: 0;
    background: transparent;
    border-radius: 0;
    cursor: pointer;
    transition: color 0.2s;
    border: none;
    text-decoration: none;
    color: var(--raspberry);
    display: inline;
    font-family: var(--font-body);
    font-size: 1em;
    line-height: 1.5;
}

.page-link-item:hover {
    background: transparent;
    color: var(--raspberry-soft);
    transform: none;
    border-color: transparent;
}

.hierarchy-index {
    width: 100%;
    min-width: 0;
    font-family: var(--font-body);
}

.hierarchy-index-empty {
    color: var(--ink-muted);
    font-family: var(--font-ui);
    padding: 8px 0;
}

.hierarchy-index-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.hierarchy-index-list .hierarchy-index-list {
    margin-top: 6px;
    margin-left: 1.35em;
    padding-left: 0.85em;
    border-left: 1px solid var(--border);
}

.hierarchy-index-item {
    margin: 0 0 6px;
    line-height: 1.5;
}

.hierarchy-index-item > .page-link-item {
    display: inline;
}

.page-editor {
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.page-editor > form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.editor-header {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 10;
}

.btn-add-element {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--raspberry);
    color: var(--on-accent);
    border: none;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(163, 22, 69, 0.35);
    transition: all 0.3s;
}

.btn-add-element:hover {
    background: var(--raspberry-deep);
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(163, 22, 69, 0.45);
}

.content-editor {
    min-height: 300px;
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    background: var(--surface);
    font-family: inherit;
    font-size: 16px;
    color: var(--ink);
    position: relative;
}

/* Кнопки сетки для выбора размера элемента */

.content-editor:focus {
    outline: none;
    border-color: var(--raspberry);
}

/* Элементы контента в сетке */
.content-block {
    margin: 0;
    position: relative;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.content-block-text {
    border: none;
    padding: 0;
}

#pageViewer .content-block-text,
#pageViewer .content-block-image-text,
#pageViewer .content-block-heading-text {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.content-block-heading-text {
    display: block;
}

.content-heading,
.edit-heading-input {
    clear: both;
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 0 0 14px;
    padding: 12px 0;
    border: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.25;
    color: var(--ink);
}

.content-heading {
    font-size: 1.55em;
    scroll-margin-top: 16px;
}

.edit-heading-input {
    font-size: 1.45em;
}

.edit-heading-input:focus {
    outline: none;
    border-top-color: var(--grass);
    border-bottom-color: var(--grass);
}

.edit-heading-input::placeholder {
    color: var(--walnut-soft);
    opacity: 0.75;
    font-weight: 500;
}

.block-text-content {
    min-height: 50px;
    padding: 8px;
    border: none;
    outline: none;
    line-height: 1.6;
    white-space: pre-wrap;
}

.block-text-content:focus {
    outline: 1px solid var(--raspberry);
    outline-offset: 2px;
}

.content-block-table {
    clear: both;
    border: none;
    padding: 0;
    background: transparent;
}

.block-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    table-layout: fixed;
}

.block-table td {
    border: 1px solid var(--border);
    padding: 10px 12px;
    min-width: 0;
    vertical-align: top;
    word-break: break-word;
    background: var(--surface);
    color: var(--ink);
    line-height: 1.45;
}

.edit-table-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 36px;
    grid-template-rows: auto 36px;
    align-items: stretch;
    width: 100%;
}

.edit-table-frame {
    position: relative;
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
}

.edit-block-table td {
    min-height: 36px;
    outline: none;
    cursor: text;
}

.edit-block-table td:focus {
    outline: 2px solid var(--raspberry);
    outline-offset: -2px;
    background: var(--beige);
}

.edit-table-col-resizer {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    margin-left: -4px;
    cursor: col-resize;
    z-index: 3;
    touch-action: none;
    user-select: none;
}

.edit-table-col-resizer::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    transform: translateX(-50%);
    background: transparent;
}

.edit-table-col-resizer:hover::after,
body.is-table-col-resizing .edit-table-col-resizer:hover::after {
    background: var(--raspberry);
}

body.is-table-col-resizing {
    cursor: col-resize;
    user-select: none;
}

body.is-table-col-resizing .edit-block-table td {
    cursor: col-resize;
}

.edit-table-add-row,
.edit-table-add-col {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    min-width: 0;
    font-size: 1.25em;
    line-height: 1;
    font-weight: 600;
}

.edit-table-add-row {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    border-radius: 0 0 0 8px;
    border-top: none;
}

.edit-table-add-col {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: 100%;
    height: 100%;
    border-radius: 0 8px 8px 0;
    border-left: none;
}

.edit-block-shell.content-block-table .edit-table-frame .block-table {
    border-radius: 8px 0 0 0;
    overflow: hidden;
}

#pageViewer .content-block-table {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

#pageViewer .block-table {
    border-radius: 8px;
    overflow: hidden;
}

.content-block-image {
    border: none;
    padding: 0;
}

.content-block-divider {
    border: none;
    padding: 0;
}

.block-divider {
    background: var(--border);
    margin: 0;
}

.block-divider-horizontal {
    width: 100%;
    height: 2px;
    margin: 10px 0;
}

.block-divider-vertical {
    width: 2px;
    min-height: 50px;
    margin: 0 10px;
    display: inline-block;
}

.block-toggle-btn {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 24px;
    height: 24px;
    background: var(--raspberry);
    color: var(--on-accent);
    border: none;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.block-toggle-btn:hover {
    opacity: 1;
}

.content-block.dragging {
    opacity: 0.5;
}

.block-image-flex-container {
    display: flex;
    align-items: stretch;
    gap: 10px;
}

.block-image-container {
    position: relative;
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    background-color: var(--surface);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    flex-shrink: 0;
    min-width: 100px;
    min-height: 100px;
    height: fit-content;
}

.block-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 5px;
    cursor: grab;
}

.image-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: var(--raspberry);
    cursor: nwse-resize;
    border-radius: 5px 0 5px 0;
    border: 2px solid var(--on-accent);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.image-resize-handle:hover {
    background: var(--raspberry-deep);
}

.block-remove-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    background: var(--raspberry);
    color: var(--on-accent);
    border: none;
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.block-remove-btn:hover {
    opacity: 1;
}

/* Кнопки добавления элементов */
.add-element-btn {
    width: 100%;
    min-height: 70px;
    padding: 15px;
    margin: 0;
    background: var(--beige);
    border: 2px dashed var(--border);
    border-radius: 8px;
    color: var(--ink-muted);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.add-element-btn:hover {
    background: var(--beige-warm);
    border-color: var(--raspberry);
    color: var(--raspberry);
}

.add-element-btn-empty {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: var(--beige);
}

.add-element-btn-right {
    flex: 1;
    margin: 0;
    min-width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: stretch;
}

.add-element-btn-bottom {
    width: 100%;
    margin-top: 0;
    min-height: 70px;
}

.content-editor .content-element {
    margin: 15px 0;
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 10px;
    position: relative;
}

.content-editor .content-element:hover {
    border-color: var(--raspberry);
}

.content-editor .element-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}

.content-editor .element-table td {
    border: 1px solid var(--border);
    padding: 8px;
    min-width: 100px;
    min-height: 30px;
}

.content-editor .element-table td:focus {
    outline: 2px solid var(--raspberry);
    outline-offset: -2px;
}

.content-editor .element-image {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 10px 0;
}

.content-editor .element-remove {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--raspberry);
    color: var(--on-accent);
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.content-editor .content-element:hover .element-remove {
    opacity: 1;
}

.content-editor .element-remove:hover {
    background: var(--raspberry-deep);
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(42, 24, 16, 0.55);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 15px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(42, 24, 16, 0.32);
    animation: modalFadeIn 0.3s;
}

.cover-crop-content {
    max-width: min(720px, 92vw);
    width: min(720px, 92vw);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.cover-crop-modal .modal-header {
    padding: 10px 14px;
    flex-shrink: 0;
}

.cover-crop-modal .modal-header h3 {
    font-size: 1.05em;
}

.cover-crop-modal .modal-close {
    width: 28px;
    height: 28px;
    font-size: 22px;
}

.cover-crop-modal .modal-body {
    padding: 10px 14px 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.cover-crop-hint {
    margin: 0 0 8px;
    color: var(--ink-muted);
    font-size: 12px;
    line-height: 1.35;
    flex-shrink: 0;
}

.cover-crop-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    flex: 1 1 auto;
    min-height: 140px;
    max-height: min(48vh, 360px);
    overflow: hidden;
    background: #1a110c;
    border-radius: 8px;
    user-select: none;
    touch-action: none;
}

.cover-crop-modal.is-portrait-crop .cover-crop-stage {
    max-height: min(56vh, 420px);
    min-height: 180px;
}

.cover-crop-canvas {
    position: relative;
    display: inline-block;
    line-height: 0;
    max-width: 100%;
    max-height: 100%;
}

.cover-crop-image {
    display: block;
    max-width: 100%;
    max-height: min(48vh, 360px);
    width: auto;
    height: auto;
    margin: 0;
}

.cover-crop-modal.is-portrait-crop .cover-crop-image {
    max-height: min(56vh, 420px);
}

.cover-crop-rect {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid var(--on-accent);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    cursor: move;
    touch-action: none;
}

.cover-crop-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--on-accent);
    border: 1px solid var(--raspberry);
    border-radius: 2px;
    box-sizing: border-box;
}

.cover-crop-handle[data-handle="nw"] {
    left: -5px;
    top: -5px;
    cursor: nwse-resize;
}

.cover-crop-handle[data-handle="ne"] {
    right: -5px;
    top: -5px;
    cursor: nesw-resize;
}

.cover-crop-handle[data-handle="sw"] {
    left: -5px;
    bottom: -5px;
    cursor: nesw-resize;
}

.cover-crop-handle[data-handle="se"] {
    right: -5px;
    bottom: -5px;
    cursor: nwse-resize;
}

.cover-crop-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.cover-crop-actions .btn {
    padding: 7px 12px;
    font-size: 13px;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.modal-header h3 {
    margin: 0;
    color: var(--ink);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--walnut-soft);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s;
}

.modal-close:hover {
    color: var(--ink);
}

.modal-body {
    padding: 20px;
}

.element-type-btn {
    width: 100%;
    padding: 20px;
    margin-bottom: 15px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.3s;
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
}

.element-type-btn:hover {
    border-color: var(--raspberry);
    background: var(--raspberry-wash);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(163, 22, 69, 0.18);
}

.element-icon {
    font-size: 32px;
}

#pageForm {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

/* Адаптивность */
@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        position: static;
    }

    .sidebar-resizer {
        display: none;
    }
}

/* ==================== СТИЛИ ДЛЯ ШАБЛОНОВ ==================== */

.template-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.template-select-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: var(--beige);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    width: 100%;
}

.template-select-btn:hover {
    background: var(--beige-warm);
    border-color: var(--raspberry);
    transform: translateY(-2px);
}

.template-icon {
    font-size: 24px;
}

.templates-manager {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 20px;
    height: 70vh;
}

.templates-list-panel {
    border-right: 1px solid var(--border);
    padding-right: 20px;
    overflow-y: auto;
}

.templates-list-panel h4 {
    margin-bottom: 15px;
    color: var(--raspberry);
}

#createTemplateBtn {
    width: 100%;
    margin-bottom: 12px;
}

.templates-list-manager {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.template-list-item {
    padding: 10px 15px;
    background: var(--beige);
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
}

.template-list-item.active {
    background: var(--raspberry);
    border-color: var(--raspberry);
    color: var(--on-accent);
}

.templates-screen {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    overflow: hidden;
}

.templates-screen-hint {
    color: var(--ink-muted);
    margin: 0 0 16px;
}

.templates-screen .page-header {
    border-bottom: 2px solid var(--border);
    padding-bottom: 15px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.template-editor-panel {
    overflow-y: auto;
    padding-left: 20px;
}

.template-editor-panel h4 {
    margin-bottom: 20px;
    color: var(--raspberry);
}

#templateContentEditor {
    min-height: 300px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    background: var(--surface);
}
