.document-settings-screen {
    max-width: 1400px;
}

.document-settings-topbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.document-settings-layout {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr) 250px;
    gap: 14px;
    align-items: start;
}

.document-template-tabs,
.document-template-editor,
.document-variables-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.document-template-tabs {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 6px;
}

.document-template-tab {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    padding: 10px 12px;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.document-template-tab em {
    color: #64748b;
    font-style: normal;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.document-template-tab.active {
    background: #eef4ff;
    border-color: #b8cff8;
    color: #1d4ed8;
}

.document-template-tab small {
    color: #ef4444;
    font-size: 10px;
    font-weight: 700;
}

.document-template-add {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 6px;
    border: 1px dashed #9db7df;
    border-radius: 6px;
    background: #f8fbff;
    color: #1d4ed8;
    padding: 10px 12px;
    font-size: 13px;
    cursor: pointer;
}

.document-template-add span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 6px;
    background: #dbeafe;
    font-weight: 800;
}

.document-template-add strong {
    font-size: 13px;
}

.document-template-add:hover {
    background: #eef4ff;
    border-color: #6ea2f2;
}

.document-template-add-secondary {
    color: #0f766e;
    border-color: #8bd3ca;
    background: #f0fdfa;
}

.document-template-editor {
    overflow: visible;
}

.document-template-editor-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: end;
    padding: 14px;
    border-bottom: 1px solid #e2e8f0;
}

.document-template-editor label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.document-template-editor input {
    height: 36px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #1f2937;
    padding: 0 10px;
    font: 13px Arial, sans-serif;
}

.document-template-active {
    flex-direction: row !important;
    align-items: center;
    padding-bottom: 10px;
    text-transform: none !important;
    font-size: 13px !important;
}

.document-template-active input {
    width: auto;
    height: auto;
}

.document-template-editor-head-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.document-editor-mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border: 1px solid #dbe4f0;
    border-radius: 999px;
    background: #f8fafc;
}

.document-editor-mode-switch button {
    min-height: 32px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #475569;
    padding: 0 12px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.document-editor-mode-switch button.active {
    background: #0f172a;
    color: #fff;
}

.document-template-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.whe-doctype-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #64748b;
    white-space: nowrap;
}

.whe-doctype-select {
    height: 34px;
    padding: 0 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #1e293b;
    font-size: 13px;
    cursor: pointer;
}

.whe-doctype-select:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.3);
}

.document-custom-template-screen .document-template-actions button[onclick="resetDocumentTemplate()"] {
    display: none;
}

.document-editor-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    overflow-x: visible;
    overflow-y: visible;
}

.document-editor-toolbar-row {
    display: flex;
    align-items: center;
    gap: 0;
    flex-wrap: nowrap;
    padding: 0 8px;
    overflow-x: visible;
    overflow-y: visible;
    white-space: nowrap;
}

.document-editor-toolbar-row-secondary {
    min-height: 42px;
    border-top: 1px solid #e2e8f0;
    background: #f4f7fb;
}

.document-editor-toolbar button,
.document-editor-toolbar select,
.document-editor-color {
    flex: 0 0 auto;
    min-height: 38px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #334155;
    padding: 0 9px;
    font-size: 14px;
    cursor: pointer;
}

.document-editor-toolbar button:hover,
.document-editor-toolbar select:hover,
.document-editor-color:hover {
    background: #eef2f7;
}

.document-editor-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 34px;
}

.document-editor-toolbar button.active {
    background: #d1d5db;
}

.document-editor-toolbar svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.document-toolbar-text-btn {
    font-size: 16px !important;
}

.document-toolbar-caret {
    color: #64748b;
    font-size: 10px;
    line-height: 1;
}

.document-editor-font-select {
    width: 160px;
    min-width: 160px;
}

.document-editor-size-select {
    width: 86px;
    min-width: 86px;
}

.document-editor-line-height-select {
    width: 82px;
    min-width: 82px;
}

.document-editor-font-select,
.document-editor-size-select,
.document-editor-line-height-select {
    height: 32px;
    min-height: 32px;
    margin: 0 3px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    padding: 0 26px 0 10px;
}

.document-editor-spacing-panel {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 6px 0;
}

.document-editor-margins-panel {
    margin-left: 18px;
    padding-left: 18px;
    border-left: 1px solid #d7e0ec;
}

.document-editor-spacing-title {
    color: #334155;
    font-size: 13px;
    font-weight: 700;
}

.document-editor-spacing-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
    text-transform: none;
}

.document-editor-spacing-field span {
    flex: 0 0 auto;
}

.document-editor-spacing-field select {
    width: 86px;
    min-width: 86px;
    height: 30px;
    min-height: 30px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #334155;
    padding: 0 26px 0 10px;
    font-size: 13px;
}

.document-editor-color {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 800;
}

.document-editor-color input {
    width: 19px;
    height: 19px;
    border: 0;
    padding: 0;
    background: transparent;
}

.document-editor-toolbar-separator {
    width: 1px;
    height: 38px;
    background: #dbe3ef;
    margin: 0 5px;
}

.document-editor-canvas {
    min-height: calc(297mm + 48px);
    overflow-x: auto;
    overflow-y: visible;
    background: #e8edf4;
    padding: 24px;
}

.document-editor-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
    box-sizing: border-box;
}

.document-template-content {
    position: relative;
    width: 210mm;
    min-height: 297mm;
    padding: 20mm;
    box-sizing: border-box;
    outline: none;
    background: #fff;
    color: #111827;
    font: 13px Arial, sans-serif;
    line-height: 1.45;
    overflow-wrap: break-word;
}

.document-template-content,
.document-template-content p,
.document-template-content div,
.document-template-content li,
.document-template-content td,
.document-template-content th,
.document-template-content span,
.document-template-content strong,
.document-template-content em,
.document-template-content u,
.document-template-content s,
.document-template-content b,
.document-template-content font {
    cursor: text;
}

.document-template-content.document-table-draw-mode {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M4 20l4.6-1 10-10a2.1 2.1 0 0 0-3-3l-10 10L4 20z' fill='%23ffffff' stroke='%231f2937' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='M14.5 6.5l3 3' stroke='%231f2937' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") 3 21, crosshair;
}

.document-template-content.document-table-draw-mode * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M4 20l4.6-1 10-10a2.1 2.1 0 0 0-3-3l-10 10L4 20z' fill='%23ffffff' stroke='%231f2937' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='M14.5 6.5l3 3' stroke='%231f2937' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") 3 21, crosshair !important;
}

.document-table-draw-marker {
    position: absolute;
    z-index: 50;
    min-width: 1px;
    min-height: 1px;
    border: 2px solid #2563eb;
    background: rgba(37, 99, 235, 0.08);
    pointer-events: none;
}

.document-table-draw-marker.document-table-draw-line {
    background: transparent;
    border: 0;
}

.document-table-draw-marker.document-table-draw-line.vertical {
    width: 0 !important;
    border-left: 3px solid #ef4444;
}

.document-table-draw-marker.document-table-draw-line.horizontal {
    height: 0 !important;
    border-top: 3px solid #ef4444;
}

.document-table-draw-marker.document-table-draw-line.is-active::after {
    content: "";
    position: absolute;
    right: -6px;
    top: -6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
}

.document-template-content:focus {
    box-shadow: inset 0 0 0 2px #bfdbfe;
}

.document-template-content h1,
.document-template-content h2,
.document-template-content h3,
.document-template-content h4,
.document-template-content h5,
.document-template-content h6,
.document-template-content p,
.document-template-content div,
.document-template-content li {
    margin-top: 0;
    margin-bottom: 0;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    box-sizing: border-box;
}

.document-template-content img {
    max-width: 100%;
    height: auto;
}

.document-template-content .doc-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.document-template-content .document-editor-resizable-table {
    table-layout: auto;
}

.document-template-content .doc-table td,
.document-template-content .doc-table th {
    position: relative;
    min-width: 36px;
    min-height: 24px;
    border: 1px solid #cbd5e1;
    padding: 6px 8px;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
    vertical-align: top;
}

.document-table-col-resize,
.document-table-row-resize,
.document-table-width-resize,
.document-table-move-handle,
.document-table-delete-handle,
.document-table-row-select,
.document-table-col-select {
    position: absolute;
    display: block;
    user-select: none;
}

.document-table-col-resize {
    top: 0;
    right: 0;
    z-index: 8;
    width: 12px;
    height: 100%;
    cursor: col-resize;
    transform: translateX(50%);
}

.document-table-row-resize {
    left: 0;
    bottom: 0;
    z-index: 8;
    width: 100%;
    height: 12px;
    cursor: row-resize;
    transform: translateY(50%);
}

.document-table-width-resize {
    top: 0;
    right: 0;
    z-index: 5;
    width: 12px;
    height: 100%;
    cursor: ew-resize;
    transform: translateX(50%);
}

.document-table-move-handle {
    top: 4px;
    left: 4px;
    z-index: 6;
    width: 16px;
    height: 16px;
    border: 1px solid #93c5fd;
    border-radius: 4px;
    background: #eff6ff;
    cursor: move;
}

.document-table-move-handle::before {
    content: "";
    position: absolute;
    inset: 3px;
    background:
        radial-gradient(circle, #2563eb 1px, transparent 1.5px) 0 0 / 5px 5px;
}

.document-table-col-resize:hover,
.document-table-row-resize:hover,
.document-table-width-resize:hover,
.document-table-resizing .document-table-col-resize:hover,
.document-table-resizing .document-table-row-resize:hover,
.document-table-resizing .document-table-width-resize:hover {
    background: rgba(37, 99, 235, 0.16);
}

.document-table-move-handle:hover {
    background: #dbeafe;
    border-color: #3b82f6;
}

.document-table-delete-handle {
    top: 4px;
    left: 24px;
    z-index: 6;
    width: 16px;
    height: 16px;
    border: 1px solid #fecaca;
    border-radius: 4px;
    background: #fff1f2;
    color: #dc2626;
    padding: 0;
    cursor: pointer;
}

.document-table-delete-handle svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.document-table-delete-handle:hover {
    background: #fee2e2;
    border-color: #f87171;
}

.document-table-delete-handle {
    display: none !important;
}

.document-table-row-select {
    top: 0;
    left: -7px;
    z-index: 4;
    width: 7px;
    height: 100%;
    cursor: pointer;
}

.document-table-col-select {
    top: -7px;
    left: 0;
    z-index: 4;
    width: 100%;
    height: 7px;
    cursor: pointer;
}

.document-table-row-select:hover,
.document-table-col-select:hover {
    background: rgba(37, 99, 235, 0.28);
}

.document-template-content .document-table-selected-cell,
.document-template-content .document-table-selected-row,
.document-template-content .document-table-selected-column {
    background: #dbeafe;
    box-shadow: inset 0 0 0 2px #2563eb;
}

.document-table-resizing {
    user-select: none;
}

.document-table-overlay {
    position: absolute;
    z-index: 24;
    pointer-events: none;
    display: none;
}

.document-table-overlay.is-visible {
    display: block;
}

.document-table-overlay-col,
.document-table-overlay-row {
    position: absolute;
    display: block;
    pointer-events: auto;
    user-select: none;
}

.document-table-overlay-col {
    top: 0;
    right: -7px;
    width: 14px;
    height: 100%;
    cursor: col-resize;
    background: rgba(37, 99, 235, 0.12);
}

.document-table-overlay-row {
    left: 0;
    bottom: -7px;
    width: 100%;
    height: 14px;
    cursor: row-resize;
    background: rgba(37, 99, 235, 0.12);
}

.document-table-overlay-col:hover,
.document-table-overlay-row:hover {
    background: rgba(37, 99, 235, 0.24);
}

.document-template-content .doc-company-logo {
    max-width: 180px;
    max-height: 70px;
}

.document-toolbar-menu {
    position: relative;
}

.document-table-menu {
    position: absolute;
    top: 34px;
    left: 0;
    z-index: 20;
    display: none;
    width: 230px;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
}

.document-table-menu.open {
    display: block;
}

.document-table-menu-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    color: #334155;
    font-size: 12px;
}

.document-table-grid {
    display: grid;
    grid-template-columns: repeat(8, 18px);
    gap: 2px;
}

.document-table-grid button {
    width: 18px;
    height: 18px;
    min-height: 18px;
    border: 1px solid #cbd5e1;
    background: #fff;
    padding: 0;
}

.document-table-grid button.active {
    background: #dbeafe;
    border-color: #60a5fa;
}

.document-table-draw-btn,
.document-table-insert-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 32px;
    margin-top: 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #334155;
    padding: 6px 8px;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.document-table-draw-btn:hover,
.document-table-insert-menu button:hover {
    background: #eef4ff;
    color: #1d4ed8;
}

.document-table-draw-btn svg,
.document-table-insert-menu button svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.document-table-insert-menu {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

.document-table-insert-menu button {
    margin-top: 2px;
}

.document-table-context-menu {
    position: fixed;
    z-index: 3000;
    min-width: 230px;
    padding: 6px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.18);
}

.document-table-context-menu button {
    display: block;
    width: 100%;
    min-height: 30px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #334155;
    padding: 6px 10px;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.document-table-context-menu button:hover {
    background: #eef4ff;
    color: #1d4ed8;
}

.document-table-context-menu button.danger {
    color: #dc2626;
}

.document-table-context-menu button.danger:hover {
    background: #fee2e2;
}

.document-table-context-menu hr {
    height: 1px;
    margin: 6px -6px;
    border: 0;
    background: #e2e8f0;
}

.document-source-dialog {
    width: 760px;
    max-width: calc(100vw - 40px);
}

.document-source-dialog textarea {
    width: 100%;
    min-height: 420px;
    box-sizing: border-box;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 10px;
    font: 12px Consolas, monospace;
}

.document-toolbar-menu-open {
    display: flex;
    align-items: center;
    gap: 10px;
}

.document-variable-token {
    display: inline-block;
    max-width: 100%;
    border-radius: 5px;
    background: #eaf2ff !important;
    color: #1d4ed8 !important;
    padding: 1px 5px;
    font: inherit;
    font-size: 1em;
    line-height: inherit;
    font-weight: inherit;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    vertical-align: baseline;
    text-decoration: none !important;
}

.documents-home-screen .directories-section-head,
.documents-section-screen .documents-section-head {
    margin-bottom: 18px;
}

.documents-home-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 0;
}

.documents-home-tab {
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    border-radius: 0;
    transition: color .15s, border-color .15s;
}

.documents-home-tab:hover {
    color: #1e40af;
}

.documents-home-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
}

.documents-section-head-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.documents-section-subtitle {
    color: #64748b;
    max-width: 820px;
}

.documents-word-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.documents-word-panel {
    background: #fff;
    border: 1px solid #dbe5ef;
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}

.documents-word-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.documents-word-search {
    width: min(420px, 100%);
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 10px 14px;
    font: inherit;
    background: #f8fafc;
}

.documents-word-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.documents-word-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    width: 100%;
    text-align: left;
    border: 1px solid #dbe5ef;
    border-radius: 14px;
    padding: 14px 16px;
    background: #f8fbff;
    transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
    cursor: pointer;
}

.documents-word-row:hover {
    border-color: #93c5fd;
    box-shadow: 0 10px 24px rgba(59, 130, 246, 0.10);
    transform: translateY(-1px);
}

.documents-word-row-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.documents-word-row-side {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.documents-word-row-main strong {
    color: #0f172a;
    font-size: 15px;
}

.documents-word-row-main small,
.documents-word-row-date {
    color: #64748b;
    font-size: 12px;
}

.documents-word-type-select {
    height: 32px;
    padding: 0 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #374151;
    font-size: 12px;
    cursor: pointer;
    flex: 0 0 auto;
    max-width: 160px;
}

.documents-word-type-select:focus {
    outline: none;
    border-color: #93c5fd;
}

.documents-word-icon-btn {
    width: 34px;
    height: 34px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
}

.documents-word-icon-btn:hover {
    background: #eef4ff;
    border-color: #93c5fd;
    color: #2563eb;
}

.documents-word-icon-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 1.8;
}

/* ── Кнопки в карточке: toggle ───────────────────────────────── */
.documents-btn-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex: 0 0 auto;
}
.documents-btn-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.documents-btn-toggle span {
    display: inline-block;
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: #cbd5e1;
    transition: background .2s;
    flex: 0 0 auto;
}
.documents-btn-toggle span::after {
    content: "";
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    margin: 3px;
    transition: transform .2s;
}
.documents-btn-toggle input:checked + span {
    background: #2563eb;
}
.documents-btn-toggle input:checked + span::after {
    transform: translateX(16px);
}
.documents-word-row:not([onclick]) {
    cursor: default;
}
.documents-word-row:not([onclick]):hover {
    transform: none;
    box-shadow: none;
    border-color: #dbe5ef;
}
}

.documents-word-delete {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 6px;
    background: #ef4444;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.documents-word-delete:hover {
    background: #dc2626;
}

.documents-word-delete svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.documents-word-error {
    margin-bottom: 12px;
    border: 1px solid #fecaca;
    background: #fff5f5;
    color: #b91c1c;
    border-radius: 14px;
    padding: 12px 14px;
}

.documents-word-variables-screen {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.documents-word-variable-group {
    background: #fff;
    border: 1px solid #dbe5ef;
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}

.documents-word-variable-group h4 {
    margin: 0 0 12px;
    font-size: 14px;
    color: #0f172a;
}

.documents-word-variable-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
}

.documents-word-variable-card,
.documents-word-variable-chip {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border: 1px solid #dbe5ef;
    border-radius: 14px;
    background: #f8fbff;
    padding: 12px;
    text-align: left;
}

.documents-word-variable-card strong,
.documents-word-variable-chip strong {
    color: #0f172a;
    font-size: 13px;
}

.documents-word-variable-card code,
.documents-word-variable-chip span {
    color: #2563eb;
    font-size: 12px;
    word-break: break-word;
}

.documents-word-variable-card span {
    color: #64748b;
    font-size: 12px;
    line-height: 1.45;
}

.documents-word-variable-chip {
    cursor: pointer;
}

.documents-word-variable-chip:hover {
    border-color: #93c5fd;
    background: #eef6ff;
}

.documents-word-editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 16px;
}

.documents-word-editor-main,
.documents-word-variables-panel {
    background: #fff;
    border: 1px solid #dbe5ef;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}

.documents-word-editor-main {
    position: relative;
    overflow: hidden;
    min-height: 720px;
}

.documents-word-editor-main-empty {
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: #f8fbff;
}

.documents-word-editor-host {
    min-height: 720px;
}

.documents-word-editor-empty {
    margin: 16px;
}

.documents-word-editor-main-empty .documents-word-editor-empty {
    width: min(680px, 100%);
    margin: 0;
}

.documents-word-editor-helper {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 2;
    margin: 0;
    background: rgba(248, 251, 255, 0.96);
    backdrop-filter: blur(2px);
}

.documents-word-fallback-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 14px;
}

.documents-word-variables-panel {
    padding: 14px;
}

.documents-word-variables-panel h3 {
    margin: 0 0 12px;
}

.documents-word-variables-scroll {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 720px;
    overflow: auto;
}

@media (max-width: 1100px) {
    .documents-word-editor-layout {
        grid-template-columns: 1fr;
    }

    .documents-word-variables-scroll {
        max-height: none;
    }
}

.document-variables-panel {
    padding: 14px;
}

.document-variables-panel h3 {
    margin: 0 0 12px;
    color: #1f2937;
    font-size: 15px;
}

.document-variables-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.document-variable-group {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
}

.document-variable-group summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 36px;
    padding: 0 10px;
    color: #1f2937;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    list-style: none;
}

.document-variable-group summary::-webkit-details-marker {
    display: none;
}

.document-variable-group summary::after {
    content: "▾";
    color: #94a3b8;
    font-size: 11px;
}

.document-variable-group:not([open]) summary::after {
    content: "▸";
}

.document-variable-group-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid #edf2f7;
}

.document-variables-list button {
    display: flex;
    align-items: center;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    padding: 8px 10px;
    color: #334155;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.document-variables-list button:hover {
    background: #eef4ff;
    border-color: #b8cff8;
    color: #1d4ed8;
}

/* ─── Word HTML Editor (whe) ─────────────────────────────────────────────── */

.whe-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 16px;
    align-items: start;
}

@media (max-width: 1100px) {
    .whe-layout {
        grid-template-columns: 1fr;
    }
}

.whe-editor-section {
    background: #fff;
    border: 1px solid #dbe5ef;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}

.whe-content {
    min-height: calc(297mm - 40mm);
}

.whe-select {
    height: 30px;
    min-height: 30px;
    margin: 0 3px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #334155;
    padding: 0 24px 0 8px;
    font-size: 13px;
    cursor: pointer;
}

.whe-table-bar {
    position: fixed;
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    white-space: nowrap;
}

.whe-table-bar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    min-height: 30px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #334155;
    padding: 0 6px;
    font-size: 13px;
    cursor: pointer;
}

.whe-table-bar button:hover {
    background: #eef2f7;
}

.whe-table-bar button:disabled {
    opacity: 0.35;
    cursor: default;
}

.whe-table-bar svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.whe-bar-sep {
    width: 1px;
    height: 24px;
    background: #dbe3ef;
    margin: 0 4px;
    flex: 0 0 auto;
}

.whe-cell-color {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
}

.whe-cell-color input[type="color"] {
    width: 20px;
    height: 20px;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.whe-bar-close {
    color: #94a3b8 !important;
}

.whe-bar-close:hover {
    color: #dc2626 !important;
    background: #fee2e2 !important;
}

.whe-cell-selected {
    background: #dbeafe !important;
    box-shadow: inset 0 0 0 2px #3b82f6;
}

.whe-var {
    display: inline;
    border-radius: 5px;
    background: #eaf2ff;
    color: #1d4ed8;
    padding: 0 3px;
    font: inherit;
    font-size: 1em;
    font-weight: inherit;
    line-height: inherit;
    white-space: nowrap;
    cursor: default;
    user-select: none;
    vertical-align: baseline;
}

.whe-grid-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 200;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}

.whe-grid-cells {
    display: grid;
    grid-template-columns: repeat(10, 18px);
    gap: 2px;
}

.whe-gcell {
    width: 18px;
    height: 18px;
    border: 1px solid #cbd5e1;
    border-radius: 2px;
    background: #fff;
    cursor: pointer;
}

.whe-gcell-active {
    background: #dbeafe;
    border-color: #60a5fa;
}

.whe-grid-label {
    margin-top: 6px;
    color: #64748b;
    font-size: 12px;
    text-align: center;
}

.whe-hidden {
    display: none !important;
}

.whe-vars-panel {
    position: sticky;
    top: 16px;
}

.whe-vars-scroll {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
}

.whe-var-group {
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.whe-var-group:last-child {
    border-bottom: 0;
}

.whe-var-group-title {
    margin-bottom: 6px;
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.whe-var-btn {
    display: block;
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    padding: 6px 10px;
    text-align: left;
    cursor: pointer;
    margin-bottom: 3px;
    font-size: 12px;
    color: #1d4ed8;
    font-weight: 500;
    transition: background .12s, border-color .12s;
}

.whe-var-btn:last-child {
    margin-bottom: 0;
}

.whe-var-btn:hover {
    border-color: #93c5fd;
    background: #eef6ff;
    color: #1e40af;
}

/* ─── WHE Toolbar (isolated from old editor CSS) ─────────────────────────── */

.whe-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.whe-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
    min-height: 42px;
}

.whe-tb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 32px;
    min-height: 32px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #334155;
    padding: 0 6px;
    font-size: 14px;
    cursor: pointer;
}

.whe-tb-btn:hover {
    background: #eef2f7;
}

.whe-tb-btn svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.whe-tb-text-btn {
    font-size: 15px !important;
    min-width: 30px;
}

.whe-tb-sep {
    display: inline-block;
    width: 1px;
    height: 26px;
    background: #dbe3ef;
    margin: 0 3px;
    flex: 0 0 auto;
}

.whe-tb-select {
    height: 30px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #fff;
    color: #334155;
    padding: 0 6px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.whe-tb-font {
    width: 140px;
}

.whe-tb-size {
    width: 60px;
}

.whe-tb-lh {
    width: 68px;
}

.whe-tb-color {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 0 4px;
    font-size: 14px;
    font-weight: 800;
    color: #334155;
    cursor: pointer;
}

.whe-tb-color input[type="color"] {
    width: 18px;
    height: 18px;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.whe-tb-caret {
    font-size: 10px;
    color: #64748b;
}

.whe-tb-table-wrap {
    position: relative;
    display: inline-flex;
}

/* ─── WHE Margins row ────────────────────────────────────────────────────── */

.whe-margins-group {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.whe-margins-label {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    white-space: nowrap;
    letter-spacing: .02em;
}

.whe-margin-field {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    color: #94a3b8;
}

.whe-margin-field span {
    white-space: nowrap;
}

.whe-margin-field input {
    width: 36px;
    height: 24px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    color: #1f2937;
    padding: 0 3px;
    font-size: 11px;
    font-family: inherit;
    text-align: center;
}

.whe-margin-field input:focus {
    outline: none;
    border-color: #60a5fa;
}

.whe-margins-preset {
    font-size: 11px !important;
    padding: 0 7px !important;
    height: 24px;
    min-height: 24px !important;
    border: 1px solid #cbd5e1 !important;
    color: #475569 !important;
}

/* ─── WHE Page breaks overlay ────────────────────────────────────────────── */

.whe-page-wrap {
    position: relative;
}

.whe-page-breaks-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
    overflow: visible;
}

.whe-page-break-line {
    position: absolute;
    left: -24px;
    right: -24px;
    height: 0;
    border-top: 2px dashed #94a3b8;
}

.whe-page-break-line::before {
    content: "";
    position: absolute;
    left: 24px;
    right: 24px;
    top: -10px;
    height: 18px;
    background: linear-gradient(to bottom, rgba(226,232,240,0.6) 0%, rgba(226,232,240,0) 100%);
    pointer-events: none;
}

.whe-page-break-num {
    position: absolute;
    top: 2px;
    left: 0;
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
    background: transparent;
    user-select: none;
    white-space: nowrap;
    line-height: 1;
}

.whe-page-break-num::before {
    content: "← Лист ";
}

.whe-page-break-num-r {
    left: auto;
    right: 0;
}

.whe-page-break-num-r::before {
    content: "Лист ";
}

.whe-page-break-num-r::after {
    content: " →";
}

/* ── Image overlay ──────────────────────────────────────────────────────────── */

.whe-image-overlay {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
    box-sizing: border-box;
}

.whe-image-overlay.whe-hidden {
    display: none;
}

/* Resize handles */
.whe-img-h {
    position: absolute;
    width: 9px;
    height: 9px;
    background: #fff;
    border: 2px solid #3b82f6;
    border-radius: 2px;
    pointer-events: all;
    box-sizing: border-box;
    transform: translate(-50%, -50%);
}
.whe-img-h[data-h="nw"] { top: 0;   left: 0;   cursor: nwse-resize; }
.whe-img-h[data-h="n"]  { top: 0;   left: 50%; cursor: ns-resize;   }
.whe-img-h[data-h="ne"] { top: 0;   left: 100%; cursor: nesw-resize; }
.whe-img-h[data-h="e"]  { top: 50%; left: 100%; cursor: ew-resize;   }
.whe-img-h[data-h="se"] { top: 100%; left: 100%; cursor: nwse-resize; }
.whe-img-h[data-h="s"]  { top: 100%; left: 50%; cursor: ns-resize;   }
.whe-img-h[data-h="sw"] { top: 100%; left: 0;   cursor: nesw-resize; }
.whe-img-h[data-h="w"]  { top: 50%; left: 0;   cursor: ew-resize;   }

/* Align/info bar below the image */
.whe-img-bar {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    background: #1e293b;
    border-radius: 6px;
    padding: 3px 6px;
    pointer-events: all;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.whe-img-align-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
    transition: background .15s, color .15s;
}
.whe-img-align-btn:hover       { background: #334155; color: #fff; }
.whe-img-align-btn.whe-img-align-active { background: #3b82f6; color: #fff; }

.whe-img-size-sep {
    width: 1px;
    height: 14px;
    background: #334155;
    margin: 0 4px;
}

.whe-img-size-lbl {
    font-size: 11px;
    color: #94a3b8;
    font-family: monospace;
}
