/* ───────────────────────────────────────────────────────────────────────────
 *  dash-code — блоки кода в сообщениях (dash-markdown: fence → .code-block) и редактор кода
 *  (dash-code.js). Подсветка — highlight.js (lib/highlight, BSD-3, локально); тема — на токенах.
 * ─────────────────────────────────────────────────────────────────────────── */
.code-block {
    margin: 8px 0; border: 1px solid var(--border-subtle); border-radius: var(--r-md);
    background: var(--surface-1); overflow: hidden; max-width: 100%; position: relative;
}
.code-head {
    display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; min-height: 32px;
    background: var(--surface-2); border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-family); font-size: 12px; color: var(--text-3);
}
.code-lang { font-weight: var(--fw-semibold); color: var(--text-2); text-transform: lowercase; }
.code-lines { margin-right: auto; font-variant-numeric: tabular-nums; }
.code-btn {
    display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px; border: 0; border-radius: var(--r-sm);
    background: none; color: var(--text-3); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
    transition: background var(--t-fast), color var(--t-fast);
}
.code-btn:hover { background: var(--bg-card-hover); color: var(--text-1); }
.code-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.code-btn::before {
    content: ""; width: 13px; height: 13px; background: currentColor; flex: 0 0 auto;
    -webkit-mask: var(--code-ic) center / contain no-repeat; mask: var(--code-ic) center / contain no-repeat;
}
.code-btn[data-code-act="copy"] { --code-ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E"); }
.code-btn[data-code-act="download"] { --code-ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3Cpath d='M12 15V3'/%3E%3C/svg%3E"); }
.code-btn[data-code-act="edit"] { --code-ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E"); }
.code-btn.done { color: var(--success-fg); }
.code-block pre {
    margin: 0; padding: 10px 14px; background: none; border: 0; border-radius: 0;
    overflow-x: auto; max-width: 100%; white-space: pre; word-break: normal; overflow-wrap: normal;
    font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; color: var(--text-1); tab-size: 4;
}
.code-block pre code { background: none; padding: 0; font: inherit; color: inherit; white-space: inherit; }
.code-block.collapsed pre { max-height: 300px; overflow-y: hidden; }
.code-block.collapsed::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 34px; height: 56px; pointer-events: none;
    background: linear-gradient(to bottom, transparent, var(--surface-1));
}
.code-more {
    display: block; width: 100%; height: 34px; border: 0; border-top: 1px solid var(--border-subtle);
    background: var(--surface-2); color: var(--text-2); font: inherit; font-size: 12px; cursor: pointer;
}
.code-more:hover { color: var(--text-1); background: var(--bg-card-hover); }
.code-block:not(.collapsed) .code-more { display: none; }

/* Подсветка highlight.js — цвета из токенов темы */
.hljs-comment, .hljs-quote, .hljs-meta { color: var(--text-3); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-section { color: var(--accent-500); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-template-tag { color: var(--success-fg); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-link { color: var(--warning-fg); }
.hljs-title, .hljs-title.function_, .hljs-name, .hljs-selector-id, .hljs-selector-class { color: var(--info-fg); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-property { color: var(--chart-5); }
.hljs-built_in, .hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--chart-4); }
.hljs-tag, .hljs-punctuation, .hljs-operator { color: var(--text-2); }
.hljs-deletion { color: var(--danger-fg); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: var(--fw-bold); }

/* ── Редактор кода (dash.codeEditor) ── */
.ce-modal { position: fixed; inset: 0; z-index: 1350; display: flex; align-items: center; justify-content: center; padding: 24px; }
.ce-modal[hidden] { display: none; }
.ce-backdrop { position: absolute; inset: 0; background: var(--bg-overlay); }
.ce-card {
    position: relative; width: min(980px, 100%); height: min(720px, 100%); display: flex; flex-direction: column;
    background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: var(--r-xl); box-shadow: var(--shadow-xl);
    overflow: hidden;
}
.ce-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border-subtle); }
.ce-head h3 { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-1); }
.ce-lang { margin-left: auto; height: 30px; padding: 0 8px; border-radius: var(--r-md); border: 1px solid var(--border-input);
    background: var(--bg-input); color: var(--text-1); font: inherit; font-size: var(--fs-sm); }
.ce-x { width: 32px; height: 32px; border: 0; border-radius: var(--r-md); background: none; color: var(--text-3); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; font-size: 18px; line-height: 1; }
.ce-x:hover { background: var(--bg-card-hover); color: var(--text-1); }
.ce-body { flex: 1; min-height: 0; display: flex; background: var(--surface-1); overflow: hidden; }
.ce-gutter {
    flex: 0 0 auto; padding: 12px 8px 12px 12px; text-align: right; user-select: none; overflow: hidden;
    font-family: var(--font-mono); font-size: 13px; line-height: 1.6; color: var(--text-3); border-right: 1px solid var(--border-subtle);
    white-space: pre; font-variant-numeric: tabular-nums; min-width: 44px;
}
.ce-area { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.ce-hl, .ce-input {
    position: absolute; inset: 0; margin: 0; padding: 12px 14px; border: 0; overflow: auto;
    font-family: var(--font-mono); font-size: 13px; line-height: 1.6; tab-size: 4; white-space: pre; word-wrap: normal;
}
.ce-hl { pointer-events: none; color: var(--text-1); background: none; }
.ce-hl code { font: inherit; background: none; padding: 0; color: inherit; }
.ce-input { resize: none; background: transparent; color: transparent; caret-color: var(--text-1); outline: none; }
.ce-input::selection { background: color-mix(in srgb, var(--accent-500) 35%, transparent); color: transparent; }
.ce-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border-subtle); }
.ce-status { margin-right: auto; font-size: var(--fs-sm); color: var(--text-3); font-variant-numeric: tabular-nums; }
body.ce-open { overflow: hidden; }
/* Режим документа: поля над текстом (название, сегментация) и перенос строк для обычного текста (без номеров строк) */
.ce-extra { padding: 10px 14px; border-bottom: 1px solid var(--border-subtle); background: var(--bg-elevated); }
.ce-extra[hidden] { display: none; }
.ce-card.ce-doc { width: min(1100px, 100%); height: min(860px, 100%); }
.ce-card.ce-wrap .ce-gutter { display: none; }
.ce-card.ce-wrap .ce-hl, .ce-card.ce-wrap .ce-input { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; overflow-x: hidden; }
.ce-doc .ce-hl, .ce-doc .ce-input { font-size: 14px; }
@media (max-width: 640px) {
    .ce-modal { padding: 0; }
    .ce-card { width: 100%; height: 100%; border-radius: 0; border: 0; }
    .code-btn span.lbl { display: none; }
}

/* Кнопка «Код» у поля ввода сообщения */
.code-compose-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: 0 0 auto;
    border: 1px solid var(--border-input); border-radius: var(--r-md); background: var(--bg-input); color: var(--text-3);
    font-family: var(--font-mono); font-size: 12px; font-weight: var(--fw-semibold); cursor: pointer;
}
.code-compose-btn:hover { color: var(--text-1); border-color: var(--accent-500); }
