/* Quill's own picker only auto-labels its built-in 'serif'/'monospace' font values (quill.snow.css
   has ::before{content:...} rules just for those two) — without a matching rule here, any other
   value in printTemplateEditor.js's FONT_WHITELIST would show as a blank item in the dropdown. */
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="arial"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="arial"]::before {
  content: "Arial";
  font-family: Arial, sans-serif;
}
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="times-new-roman"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="times-new-roman"]::before {
  content: "Times New Roman";
  font-family: "Times New Roman", serif;
}
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="georgia"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="georgia"]::before {
  content: "Georgia";
  font-family: Georgia, serif;
}
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="verdana"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="verdana"]::before {
  content: "Verdana";
  font-family: Verdana, sans-serif;
}
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="courier-new"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="courier-new"]::before {
  content: "Courier New";
  font-family: "Courier New", monospace;
}

/* Applies the actual font inside the editor once picked — same idea as quill.snow.css's own
   .ql-font-serif/.ql-font-monospace rules, just for the names added above. */
.ql-editor .ql-font-arial { font-family: Arial, sans-serif; }
.ql-editor .ql-font-times-new-roman { font-family: "Times New Roman", serif; }
.ql-editor .ql-font-georgia { font-family: Georgia, serif; }
.ql-editor .ql-font-verdana { font-family: Verdana, sans-serif; }
.ql-editor .ql-font-courier-new { font-family: "Courier New", monospace; }

/* Line-spacing picker: printTemplateEditor.js registers this format from scratch (Quill has no
   built-in one), so unlike the font picker above there's no default label at all to override —
   every value here, including the unset/default one, needs its own ::before rule or the dropdown
   shows blank items. */
/* Quill's own header/font/size pickers each get an explicit width in quill.snow.css — a custom
   picker like this one has none, and defaults too narrow to fit "По умолчанию" without clipping. */
.ql-snow .ql-picker.ql-lineheight {
  width: 130px;
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label::before,
.ql-snow .ql-picker.ql-lineheight .ql-picker-item::before {
  content: "По умолчанию";
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label[data-value="1"]::before,
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="1"]::before {
  content: "1.0";
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label[data-value="1-15"]::before,
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="1-15"]::before {
  content: "1.15";
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label[data-value="1-5"]::before,
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="1-5"]::before {
  content: "1.5";
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label[data-value="2"]::before,
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="2"]::before {
  content: "2.0";
}

/* Applies the actual spacing inside the editor once picked. */
.ql-editor .ql-lineheight-1 { line-height: 1; }
.ql-editor .ql-lineheight-1-15 { line-height: 1.15; }
.ql-editor .ql-lineheight-1-5 { line-height: 1.5; }
.ql-editor .ql-lineheight-2 { line-height: 2; }

/* quill.snow.css zeroes out every <p>'s margin (".ql-editor p,...{margin:0;padding:0}") to keep
   the editor looking like one continuous block of text. Print/preview never loads that stylesheet,
   so its <p> tags fall back to the plain browser default (roughly 1em top/bottom) instead — the
   same template looks tighter in the editor than what actually gets printed, and there was no way
   to see or control that spacing while editing. Restoring an explicit, equal margin here (loads
   after quill.snow.css, so it wins on equal specificity) makes the editor match what
   PrintTemplateRenderer.EditorCompatibilityStyles applies on the print/preview side — see that
   file for the matching rule, the two values must be kept in sync by hand, same as the font rules
   above. A paragraph typed with Shift+Enter (a soft line break within the same <p>, not a new one)
   still has no gap — that's the way to control/remove spacing between specific lines without
   touching this default. */
.ql-editor p { margin: 0 0 1em 0; }

/* Paragraph-spacing picker: lets a specific paragraph override the 1em default above (smaller or
   larger) — same registered-from-scratch format as the line-spacing picker, so it needs the same
   own-label treatment (no default label exists to override) and its own explicit picker width. */
.ql-snow .ql-picker.ql-pspacing {
  width: 130px;
}
.ql-snow .ql-picker.ql-pspacing .ql-picker-label::before,
.ql-snow .ql-picker.ql-pspacing .ql-picker-item::before {
  content: "По умолчанию";
}
.ql-snow .ql-picker.ql-pspacing .ql-picker-label[data-value="0"]::before,
.ql-snow .ql-picker.ql-pspacing .ql-picker-item[data-value="0"]::before {
  content: "0em";
}
.ql-snow .ql-picker.ql-pspacing .ql-picker-label[data-value="0-5"]::before,
.ql-snow .ql-picker.ql-pspacing .ql-picker-item[data-value="0-5"]::before {
  content: "0.5em";
}
.ql-snow .ql-picker.ql-pspacing .ql-picker-label[data-value="1"]::before,
.ql-snow .ql-picker.ql-pspacing .ql-picker-item[data-value="1"]::before {
  content: "1em";
}
.ql-snow .ql-picker.ql-pspacing .ql-picker-label[data-value="1-5"]::before,
.ql-snow .ql-picker.ql-pspacing .ql-picker-item[data-value="1-5"]::before {
  content: "1.5em";
}
.ql-snow .ql-picker.ql-pspacing .ql-picker-label[data-value="2"]::before,
.ql-snow .ql-picker.ql-pspacing .ql-picker-item[data-value="2"]::before {
  content: "2em";
}

/* Applies the actual spacing inside the editor once picked — a two-class selector (.ql-editor
   .ql-pspacing-0) beats the single-class default rule above regardless of stylesheet order. */
.ql-editor .ql-pspacing-0 { margin-bottom: 0; }
.ql-editor .ql-pspacing-0-5 { margin-bottom: 0.5em; }
.ql-editor .ql-pspacing-1 { margin-bottom: 1em; }
.ql-editor .ql-pspacing-1-5 { margin-bottom: 1.5em; }
.ql-editor .ql-pspacing-2 { margin-bottom: 2em; }

/* ── Страница редактора печатной формы (/settings/print-templates/…) ─────────────────────────
   Слева словарь полей, в центре лист выбранного размера, справа настройки листа и показа. */
.pte-header .pte-name { flex: 1 1 260px; max-width: 420px; }
.pte-header .pte-object { color: var(--mud-palette-text-secondary); font-weight: 600; font-size: .9rem; }
.pte-header .pte-switch { margin: 0; }
.pte-header .pte-header-actions { margin-left: auto; display: flex; gap: 8px; }

.pte-layout {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 270px;
    gap: 14px;
    height: calc(100vh - 150px);
    min-height: 520px;
}

.pte-panel {
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    border-radius: 16px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-divider);
}

/* Словарь полей */
.pte-fields-hint { margin: 8px 2px; font-size: .78rem; color: var(--mud-palette-text-secondary); }
.pte-fields-group {
    margin: 14px 2px 4px;
    font-size: .72rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--mud-palette-text-primary);
}
/* Поле в словаре — та же фиолетовая плашка, что и в тексте листа; по одной в строке. */
.pte-field-list { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.pte-field {
    max-width: 100%;
    padding: 2px 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: rgba(139, 92, 246, .14);
    color: color-mix(in srgb, #6D28D9 75%, var(--mud-palette-text-primary));
    text-align: left;
    cursor: pointer;
    font: inherit;
    font-size: .85rem;
    line-height: 1.5;
}
    .pte-field:hover:not(:disabled) { background: rgba(139, 92, 246, .24); border-color: rgba(139, 92, 246, .45); }
    .pte-field:focus-visible { outline: 2px solid rgba(139, 92, 246, .6); outline-offset: 1px; }
    .pte-field:disabled { opacity: .45; cursor: default; }

/* Центр: панель над листом и сам лист */
.pte-center { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pte-center-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 6px 8px;
    margin-bottom: 8px;
    border-radius: 12px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-divider);
}
.pte-center-bar .pte-sample { flex: 1 1 320px; max-width: 520px; }
.pte-center-bar .mud-input-control { margin: 0 !important; }
.pte-toolbar-host { flex: 1 1 auto; min-width: 0; }
.pte-toolbar-host .ql-toolbar.ql-snow { border: 0; padding: 2px 0; }
.pte-hidden { display: none !important; }

.pte-canvas {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 20px;
    border-radius: 16px;
    background: #E9EAEE;
}

/* Лист: реальный размер (мм) и поля — из настроек; пунктир каждые высоту листа — граница страницы. */
.pte-sheet {
    display: block;
    margin: 0 auto;
    box-sizing: border-box;
    background-color: #fff;
    background-image: repeating-linear-gradient(to bottom,
        transparent 0, transparent calc(var(--pte-page-height, 297mm) - 1px),
        #C7CAD1 calc(var(--pte-page-height, 297mm) - 1px), #C7CAD1 var(--pte-page-height, 297mm));
    box-shadow: 0 2px 10px rgba(15, 23, 42, .12);
    border: 0;
}
.pte-sheet #pte-editor.ql-container.ql-snow { border: 0; font-size: 16px; font-family: "Times New Roman", serif; }
.pte-sheet #pte-editor .ql-editor { padding: 0; min-height: 100%; overflow: visible; }
.pte-preview { background-image: none; }

/* Плашка поля в тексте */
.ql-editor .pt-field > span {
    display: inline-block;
    padding: 0 6px;
    border-radius: 6px;
    background: rgba(139, 92, 246, .14);
    color: #5B21B6;
    font-size: .85em;
    font-family: Arial, sans-serif;
    line-height: 1.5;
    white-space: nowrap;
    cursor: default;
}
.ql-editor .pt-field.pt-field-unknown > span { background: rgba(239, 68, 68, .14); color: #B91C1C; }
/* Плашка таблицы с перечнем колонок может быть длинной — переносится, а не вылезает за лист. */
.ql-editor .pt-field > span { max-width: 100%; white-space: normal; }
/* Перетаскивание: поле из словаря и плашку в тексте можно тянуть; черта — куда встанет поле. */
.pte-field[draggable="true"] { cursor: grab; }
.ql-editor .pt-field > span { cursor: grab; }
.ql-editor .pt-field.pt-field-dragging > span { opacity: .45; }
body.pte-dragging, body.pte-dragging * { cursor: grabbing !important; user-select: none; }
.pte-drop-caret {
    display: none;
    position: absolute;
    width: 2px;
    margin-left: -1px;
    border-radius: 1px;
    background: #7C3AED;
    box-shadow: 0 0 0 2px rgba(124, 58, 237, .18);
    pointer-events: none;
    z-index: 5;
}
/* Выбранная щелчком плашка: её формат — в правой панели. */
.ql-editor .pt-field.pt-field-selected > span { outline: 2px solid rgba(139, 92, 246, .7); outline-offset: 1px; }

/* Правая панель: выбранное поле */
.pte-selected {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--mud-palette-divider);
}
.pte-selected-name { font-weight: 600; font-size: .95rem; margin: 0 2px 2px; }
.pte-selected-hint { margin: 0 2px 14px; }
.pte-check { margin-left: -6px; }
    .pte-check .mud-typography { font-size: .85rem; }
.pte-formats { display: flex; flex-direction: column; }
    .pte-formats .mud-radio { display: flex; width: 100%; margin: 0; }
    .pte-formats .mud-typography { font-size: .85rem; }

/* Настройки листа */
.pte-settings-title {
    margin: 4px 2px 10px;
    font-size: .72rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.pte-orientation { width: 100%; }
/* Как печатается форма — по её полям; не настройка, только пояснение. */
.pte-print-mode {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin: 0 0 16px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(139, 92, 246, .08);
    font-size: .8rem;
    line-height: 1.35;
    color: var(--mud-palette-text-primary);
}
    .pte-print-mode .mud-icon-root { flex: 0 0 auto; margin-top: 1px; color: #7C3AED; }
.pte-fields-group-hint { margin: -2px 2px 6px; font-size: .74rem; }
.pte-settings-hint { margin: 2px 2px 0; font-size: .78rem; color: var(--mud-palette-text-secondary); }
.pte-settings-warn { margin-top: 6px; font-size: .8rem; color: #B45309; }

@media (max-width: 1200px) {
    .pte-layout { grid-template-columns: 220px minmax(0, 1fr); height: auto; }
    .pte-settings { grid-column: 1 / -1; }
}
