/*
 * Стили контента, собранного визуальным редактором `<news-editor>`.
 *
 * Глобальные, а не scoped внутри компонента: одна и та же разметка выводится в
 * четырёх местах — в редакторе, в предпросмотре, в уведомлении личного кабинета
 * и в истории рассылки. Пока стили жили в компоненте, письмо выглядело правильно
 * только в самом редакторе.
 *
 * `.editor-content` — общая обёртка: вешаем её везде, где выводим такой HTML.
 * Портировано из gr0326 (см. agent-rules/newsletter.md).
 */

/*
 * Tailwind preflight сбрасывает маркеры у ul/ol глобально (специфичность 0,0,1),
 * поэтому возвращаем их внутри контейнеров с контентом: класс + тег перебивает
 * preflight независимо от порядка подключения файлов.
 */
.editor-content ul,
.news-editor__surface ul,
.news-editor__preview-body ul,
.news-body ul,
.notification-item_text ul,
.admin-nl-hist__html ul {
    list-style: disc outside;
    padding-left: 1.4em;
    margin: 0.5em 0;
}

.editor-content ol,
.news-editor__surface ol,
.news-editor__preview-body ol,
.news-body ol,
.notification-item_text ol,
.admin-nl-hist__html ol {
    list-style: decimal outside;
    padding-left: 1.6em;
    margin: 0.5em 0;
}

.editor-content li,
.news-editor__surface li,
.news-editor__preview-body li,
.news-body li,
.notification-item_text li,
.admin-nl-hist__html li {
    margin: 0.25em 0;
}

.editor-content a,
.news-editor__preview-body a,
.notification-item_text a,
.admin-nl-hist__html a {
    color: #1a5fb4;
    text-decoration: underline;
}

/* В contenteditable ссылки по умолчанию не выделены — подсвечиваем явно. */
.news-editor__surface a {
    color: #1a5fb4;
    text-decoration: underline;
}

.editor-content img,
.news-editor__preview-body img,
.notification-item_text img,
.admin-nl-hist__html img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/*
 * Колонки. Редактор вставляет их таблицей: почтовые клиенты не понимают
 * ни flex, ни grid, а таблица одинаково раскладывается и в письме, и на сайте.
 */
.editor-cols {
    width: 100%;
    border-collapse: collapse;
    margin: 1.2em 0;
}

.editor-cols td {
    vertical-align: top;
    padding: 0 10px;
}

.editor-cols td:first-child {
    padding-left: 0;
}

.editor-cols td:last-child {
    padding-right: 0;
}

.news-editor__surface .editor-cols td {
    outline: 1px dashed rgba(157, 101, 63, 0.35);
    min-height: 40px;
}

/*
 * Видео: <figure class="editor-video"> с iframe (YouTube / Rutube / VK Видео /
 * Дзен) либо с нативным <video> для прямых ссылок на файл. Пропорция 16:9
 * держится через aspect-ratio — плеер подстраивается под ширину контейнера.
 */
.editor-video {
    margin: 1.2em 0;
    max-width: 100%;
}

.editor-video iframe,
.editor-video video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    border: 0;
    border-radius: 10px;
    background: #000;
}

/* В редакторе плеер не перехватывает клики — иначе нельзя поставить каретку
   рядом с блоком и удалить его. Клик по обёртке выделяет весь блок. */
.news-editor__surface .editor-video {
    position: relative;
}

.news-editor__surface .editor-video iframe {
    pointer-events: none;
}

.news-editor__surface .editor-video::after {
    content: 'Видео (в редакторе не воспроизводится)';
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: rgba(64, 53, 40, 0.5);
}

/* === Хром визуального редактора (тулбар, поверхности, модалки) ===
   Портирован из gr0326: кнопки форматирования, панель картинки, тулбар блока
   колонок, диалоги ссылки и видео. Сам контент оформляет editor-content.css. */

.news-editor {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}

.news-editor__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: rgba(64, 99, 59, 0.04);
    border-bottom: 1px solid var(--line);
}

.news-editor__btn {
    padding: 6px 10px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
}

.news-editor__btn:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.06);
}

.news-editor__btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.news-editor__btn.is-pressed,
.news-editor__btn.is-active {
    background: #3D5632;
    color: #fff;
}

.news-editor__btn--mode {
    margin-left: auto;
}

.news-editor__sep {
    width: 1px;
    height: 18px;
    background: var(--line);
    margin: 0 4px;
}

.news-editor__spacer {
    flex: 1;
}

.news-editor__surface {
    min-height: 320px;
    padding: 14px 18px;
    line-height: 1.55;
    font-size: 15px;
    color: var(--ink);
    outline: none;
}

.news-editor__surface:focus {
    background: rgba(64, 99, 59, 0.02);
}

.news-editor__surface img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
    cursor: pointer;
}

.news-editor__surface img.is-selected {
    outline: 2px solid #5A7FAF;
    outline-offset: 2px;
}

/* Wrap нужен для абсолютного позиционирования тулбара/ручки картинки. */
.news-editor__surface-wrap {
    position: relative;
}

/* Тулбар выделенной картинки: пресеты ширины + удалить. */
.news-editor__img-toolbar {
    position: absolute;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    background: #fff;
    border: 1px solid rgba(118, 154, 201, 0.5);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
    pointer-events: auto;
    user-select: none;
}

.news-editor__img-toolbar button { white-space: nowrap; }

.news-editor__img-toolbar button {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #21212d;
}

.news-editor__img-toolbar button:hover {
    background: rgba(118, 154, 201, 0.1);
    border-color: rgba(118, 154, 201, 0.5);
}

.news-editor__img-toolbar-remove {
    color: #c75454 !important;
    font-size: 16px !important;
    line-height: 1;
}

.news-editor__img-toolbar-sep {
    width: 1px;
    align-self: stretch;
    background: rgba(255, 255, 255, 0.3);
    margin: 0 2px;
}

.news-editor__hint {
    margin: 0 0 6px;
    font-size: 12px;
    color: #8a857c;
    line-height: 1.4;
}

/* Обтекание: редактор и превью должны вести себя одинаково с письмом/уведомлением.
   После плавающей картинки контейнер очищает float, чтобы следующий блок не наезжал. */
.news-editor__surface::after,
.news-editor__preview-body::after {
    content: "";
    display: block;
    clear: both;
}

.news-editor__preview-body img[align="left"] { float: left; margin: 0 16px 8px 0; }

.news-editor__preview-body img[align="right"] { float: right; margin: 0 0 8px 16px; }

/* Меню «Колонки» */
.news-editor__cols-menu-wrap { position: relative; display: inline-block; }

.news-editor__cols-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 20;
    background: #fff;
    border: 1px solid rgba(118, 154, 201, 0.5);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
    padding: 4px;
    min-width: 190px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.news-editor__cols-menu button {
    text-align: left;
    padding: 8px 10px;
    border: 0;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #21212d;
}

.news-editor__cols-menu button:hover { background: rgba(118, 154, 201, 0.14); }

/* Колонки-блоки видны пунктиром в редакторе и превью (в письме границы нет — это только CSS админки). */
.news-editor__surface .editor-cols td.editor-col,
.news-editor__preview-body .editor-cols td.editor-col {
    outline: 1px dashed rgba(118, 154, 201, 0.5);
    outline-offset: -2px;
}

.news-editor__block-toolbar { gap: 6px; }

.news-editor__block-label { font-size: 12px; color: #5c6584; padding: 0 4px; }

/* Ручка resize — маленький квадрат в правом нижнем углу выделенной картинки. */
.news-editor__img-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #5A7FAF;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    z-index: 10;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.news-editor__surface h2,
.news-editor__surface h3 {
    font-family: "Book Antiqua", "Palatino Linotype", serif;
    color: var(--ink);
    margin: 16px 0 8px;
}

.news-editor__surface p {
    margin: 0 0 10px;
}

.news-editor__html {
    width: 100%;
    min-height: 320px;
    padding: 14px 18px;
    border: 0;
    background: #fbfbf8;
    font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
}

.news-editor__html:focus {
    outline: none;
    background: #fff;
}

.news-editor__preview {
    border-top: 1px solid var(--line);
    padding: 14px 18px;
    background: rgba(0, 0, 0, 0.02);
}

.news-editor__preview-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--textPrimary);
    margin-bottom: 10px;
}

.news-editor__preview-body {
    line-height: 1.55;
    font-size: 15px;
    color: var(--ink);
}

.news-editor__error {
    margin: 0;
    padding: 10px 14px;
    background: rgba(199, 84, 84, 0.12);
    color: var(--danger, #c75454);
    font-size: 12px;
    border-top: 1px solid var(--line);
}

/* Модалка для ввода адреса ссылки в news-editor. */
.news-editor__overlay {
    position: fixed;
    inset: 0;
    background: rgba(33, 33, 45, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1200;
}

.news-editor__dialog {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    width: min(440px, 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.news-editor__dialog h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.news-editor__dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.news-editor__btn--primary {
    background: var(--admin-accent, #769AC9);
    color: #fff;
    border-color: var(--admin-accent, #769AC9);
}
