:root{
  /* Page layout: 1520px — оптимальная ширина для двухколоночного редактора
     внутри Studio: список и форма не зажаты, но и не расползаются на 4K. */
  --editor-page-max: 1520px;
  --editor-page-pad: clamp(14px, 1.6vw, 22px);
  --editor-sidebar-w: 316px;
  --editor-sticky-top: 16px;

  /* Card / section tuning */
  --editor-card-radius: var(--editor-radius-lg, 14px);
  --editor-card-pad: 18px;

  /* Field grids */
  --editor-fields-gap: 14px;

  /* Table list mode */
  --editor-table-idx: 44px;
  --editor-table-del: 44px;
  --editor-table-col2: 160px;
}

/* -------------------------------------------------------------
   Per-editor accents
------------------------------------------------------------- */
body[data-editor="crafts"]{ --editor-accent:#22c55e; }
body[data-editor="mobs"],
body[data-editor="bots_mobs"]{ --editor-accent:#f43f5e; }
body[data-editor="events"]{ --editor-accent:#60a5fa; }
body[data-editor="scenario"]{ --editor-accent:#a78bfa; }
body[data-editor="vouchers"]{ --editor-accent:#f59e0b; }
body[data-editor="worlds"]{ --editor-accent:#38bdf8; }
body[data-editor="aethers"]{ --editor-accent:#fb923c; }
body[data-editor="dungeons"]{ --editor-accent:#e879f9; }
body[data-editor="quests"]{ --editor-accent:#8b5cf6; }
body[data-editor="bots_npc"]{ --editor-accent:#38bdf8; }
body[data-editor="bots_info"]{ --editor-accent:#f97316; }
body[data-editor="items"]{ --editor-accent:#22c55e; }
body[data-editor="warehouse"],
body[data-editor="warehouses"]{ --editor-accent:#14b8a6; }
body[data-editor="accounts"]{ --editor-accent:#60a5fa; }
body[data-editor="requests"]{ --editor-accent:#fbbf24; }
body[data-editor="guests"]{ --editor-accent:#2dd4bf; }
body[data-editor="settings"]{ --editor-accent:#818cf8; }
body[data-editor="database"]{ --editor-accent:#34d399; }

/* -------------------------------------------------------------
   Page shell
------------------------------------------------------------- */
.editor-page{
  position:relative;
  isolation:isolate;
  max-width:var(--editor-page-max);
  margin:0 auto;
  padding:var(--editor-page-pad);
}

/* Мягкая подсветка сверху осталась, но еле заметная: она задаёт «воздух»
   над заголовком и не спорит с содержимым. */
.editor-page::before{
  content:"";
  position:absolute;
  inset:0 0 auto;
  height:96px;
  z-index:-1;
  pointer-events:none;
  background:linear-gradient(180deg, color-mix(in srgb, var(--editor-primary) 6%, transparent), transparent 80%);
}

/* Полноэкранные вкладки (сценарии): общий токен каркаса, но без страничной
   «бумаги» — отступов, максимальной ширины и декоративной подсветки.
   Так у всех вкладок один и тот же предок .editor-page, а вёрстка остаётся
   приложением: липкая шапка + своя колонка навигатора. */
.editor-page--app{
  max-width:none;
  margin:0;
  padding:0;
  min-height:0;
}

.editor-page--app::before{display:none;}

.editor-page-header{
  position:relative;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  padding:0 0 16px;
  margin-bottom:0;
  border-bottom:1px solid var(--editor-line);
}

.editor-page-title{
  display:flex;
  align-items:center;
  gap:14px;
  min-width:0;
}

/* Иконка вкладки — квадратная плитка с мягкой заливкой вместо декоративной
   звёздочки. Она же служит якорем для глаза у заголовка. */
.editor-page-title::before{
  display:none;
}

.editor-page-title > i{
  flex:0 0 40px;
  width:40px;
  height:40px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:17px;
  border-radius:var(--editor-radius-md);
  background:color-mix(in srgb, var(--editor-accent) 14%, transparent);
  border:1px solid color-mix(in srgb, var(--editor-accent) 26%, transparent);
  color:var(--editor-accent);
  /* Tailwind-классы text-accent/text-xl на иконке больше не нужны: размер
     задаёт плитка, а не утилита. */
  line-height:1;
}

.editor-page-title h1{
  margin:0;
  font-size:var(--editor-text-xl);
  font-weight:700;
  letter-spacing:-.015em;
  line-height:1.2;
}

.editor-page-sub{
  margin-top:3px;
  color:var(--editor-text-muted);
  font-size:var(--editor-text-md);
  line-height:1.45;
  max-width:78ch;
}

.editor-page-actions{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:center;
  justify-content:flex-end;
}

.editor-page-actions .editor-btn,
.editor-page-actions .editor-icon-btn{
  flex:0 0 auto;
}

.editor-page-actions > *{
  flex-shrink:0;
}

@media (max-width:900px){
  .editor-page-header{
    flex-direction:column;
    align-items:stretch;
  }

  .editor-page-actions{
    justify-content:flex-start;
  }
}

@media (max-width:640px){
  .editor-page-actions{
    display:grid;
    grid-template-columns:repeat(auto-fit, minmax(140px, 1fr));
    align-items:stretch;
  }

  .editor-page-actions .editor-btn,
  .editor-page-actions .editor-icon-btn{
    width:100%;
    justify-content:center;
  }
}

/* Sidebar header + filters */
.editor-sidebar-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

.editor-sidebar-meta{
  font-size:var(--editor-text-xs);
  color:var(--editor-text-muted);
}

/* Сайдбар плотнее основной области: там список из десятков строк, и каждый
   лишний пиксель отступа — минус видимая запись. */
.editor-shell--docked > .editor-dock-sidebar .editor-dock-pad{
  padding:14px;
}

.editor-dock-sidebar .editor-search input,
.editor-dock-sidebar select.editor-input{
  min-height:34px;
  height:34px;
  font-size:var(--editor-text-sm);
}

/* Заголовок «Список предметов» + счётчик в сайдбаре. */
.editor-dock-sidebar .text-sm.font-semibold{
  font-size:var(--editor-text-md);
  font-weight:600;
  color:var(--editor-text);
}

.editor-dock-sidebar .text-xs{
  font-size:var(--editor-text-xs);
  line-height:1.4;
}

.editor-sidebar-filters{
  display:grid;
  gap:8px;
}

.editor-sidebar-filters.two-col{
  grid-template-columns:repeat(2, minmax(0, 1fr));
}

@media (max-width:520px){
  .editor-sidebar-filters.two-col{grid-template-columns:1fr;}
}

.editor-badge{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
  border:1px solid var(--editor-badge-border);
  background:var(--editor-badge-bg);
  color:var(--editor-text);
}

/* -------------------------------------------------------------
   Sidebar + main grid
------------------------------------------------------------- */
.editor-shell{
  display:grid;
  grid-template-columns:minmax(280px, var(--editor-sidebar-w)) minmax(0, 1fr);
  gap:16px;
  align-items:start;
  margin-top:16px;
}

.editor-shell > *{
  min-width:0;
}

/* Docked layout (single surface): Sidebar + Main share one frame.
   Important: do NOT set overflow:hidden (would break sticky sidebars). */
/* Сайдбар и форма живут в одной «рамке»: общая поверхность, один контур,
   разделитель между колонками. */
.editor-shell--docked{
  gap:0;
  border:1px solid var(--editor-line);
  border-radius:var(--editor-card-radius);
  background:var(--editor-surface);
  box-shadow:none;
}

/* Скругляем углы у самих колонок, а не у контейнера: overflow:hidden/clip
   обрезал бы выпадающие списки внутри формы. */
.editor-shell--docked > .editor-dock-sidebar{
  border-right:1px solid var(--editor-line);
  border-radius:var(--editor-card-radius) 0 0 var(--editor-card-radius);
  background:var(--editor-shell-sidebar-bg);
}

.editor-shell--docked > .editor-dock-main{
  border-radius:0 var(--editor-card-radius) var(--editor-card-radius) 0;
}

.editor-shell--docked > .editor-dock-main{
  background:var(--editor-shell-main-bg);
}

.editor-dock-pad{
  padding:var(--editor-card-pad);
}

@media (max-width:1100px){
  .editor-shell--docked > .editor-dock-sidebar{
    border-right:none;
    border-bottom:1px solid var(--editor-line);
    border-radius:var(--editor-card-radius) var(--editor-card-radius) 0 0;
  }
  .editor-shell--docked > .editor-dock-main{
    border-radius:0 0 var(--editor-card-radius) var(--editor-card-radius);
  }
}

.editor-sidebar{
  position:sticky;
  top:var(--editor-sticky-top);
  align-self:start;
  min-width:0;
}

.editor-main{min-width:0;}

@media (max-width:1100px){
  .editor-shell{grid-template-columns:1fr;}
  .editor-sidebar{position:relative;top:0;}
}

/* Standard card wrapper */
/* Карточка-секция: одна поверхность и волосяная рамка. Ни градиента, ни
   размытия — на длинной форме их накапливалось столько, что форма «плыла». */
.editor-panel-card{
  background:var(--editor-surface);
  border:1px solid var(--editor-line);
  border-radius:var(--editor-card-radius);
  padding:var(--editor-card-pad);
  box-shadow:none;
}

/* -------------------------------------------------------------
   Sections + field grids
------------------------------------------------------------- */
.editor-section{
  padding:var(--editor-space, 14px);
}

/* Сетка полей формы: колонок столько, сколько помещается. На 1280px это три
   колонки, на планшете две, на телефоне одна — без медиазапросов и без
   «полей на пол-экрана». */
.editor-form-grid-2{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap:var(--editor-fields-gap) 18px;
  align-items:start;
}

/* Поле на всю строку: длинный текст, списки, большие блоки. */
.editor-form-grid-2 > [data-field-path]{
  min-width:0;
}

/* -------------------------------------------------------------
   List "table mode"
------------------------------------------------------------- */
.editor-list{
  display:flex;
  flex-direction:column;
  gap:12px;
  min-width:0;
}

/* «Добавить элемент» — по ширине текста, а не на всю карточку. */
.editor-list-add{align-self:flex-start;}

/* Элемент списка в одну строку: #N, поля, корзина.
   Поля внутри переносятся сами, корзина остаётся справа. */
.editor-list-item--row{
  flex-direction:row;
  align-items:flex-end;
  gap:10px;
  padding:10px 12px;
}

.editor-list-item--row > .editor-list-item-idx{margin-bottom:11px;}
.editor-list-item--row > .editor-list-item-del{margin-bottom:1px;}

/* Компактный элемент: тонкая строка «#N … корзина» и поля под ней. */
.editor-list-item--compact{
  padding:10px 12px;
  gap:8px;
}

.editor-list-item-bar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  min-width:0;
}

.editor-list-item-idx{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  flex:0 0 auto;
  min-width:26px;
  height:22px;
  padding:0 7px;
  border-radius:999px;
  border:1px solid var(--editor-soft-border);
  background:var(--editor-light-bg, rgba(255,255,255,.045));
  color:var(--editor-text-muted);
  font-size:11px;
  font-weight:700;
  letter-spacing:.02em;
}

/* Поля элемента: сами укладываются в строки по своей «ширине» — так один
   слот дропа помещается в строку, а не занимает три этажа. */
.editor-item-fields{
  display:flex;
  flex-wrap:wrap;
  align-items:flex-end;
  gap:10px;
  flex:1 1 auto;
  min-width:0;
}

.editor-item-cell{min-width:0;}
.editor-item-cell.is-narrow{flex:1 1 104px;max-width:190px;}
.editor-item-cell.is-mid{flex:2 1 190px;}
.editor-item-cell.is-wide{flex:1 1 100%;}

@media (max-width:640px){
  .editor-item-cell.is-narrow{max-width:none;}
  .editor-list-item--row > .editor-list-item-idx{align-self:center;margin-bottom:0;}
}

.editor-list-table{
  gap:0;
  border:1px solid var(--editor-line);
  border-radius:var(--editor-radius-md);
  overflow:clip;
  background:var(--editor-surface);
}

.editor-list-table-header,
.editor-list-table-row{
  display:grid;
  grid-template-columns:var(--editor-list-table-cols, var(--editor-table-idx) minmax(0,1fr) var(--editor-table-col2) var(--editor-table-del));
  gap:10px;
  align-items:center;
  padding:10px 12px;
  min-width:0;
}

@media (min-width:768px){
  .editor-list-table-header,
  .editor-list-table-row{
    grid-template-columns:var(--editor-list-table-cols-md, var(--editor-list-table-cols, var(--editor-table-idx) minmax(0,1fr) var(--editor-table-col2) var(--editor-table-del)));
  }
}

.editor-list-table-header{
  position:sticky;
  top:0;
  z-index:1;
  font-size:12px;
  font-weight:700;
  color:var(--editor-text-muted);
  background:var(--editor-light-bg);
  border-bottom:1px solid var(--editor-soft-border);
}

.editor-list-table-row{
  border-top:1px solid var(--editor-soft-border);
  transition:background-color .14s ease;
}

.editor-list-table-row:first-of-type{border-top:0;}

.editor-list-table-row:hover{
  background:var(--editor-light-bg);
}

.editor-list-table-idx{
  font-size:12px;
  color:var(--editor-text-muted);
}

.editor-list-table-cell{min-width:0;}
.editor-list-table-cell .editor-field{
  padding:0;
  border:0;
  background:transparent;
  box-shadow:none;
  backdrop-filter:none;
}
.editor-list-table-cell .editor-field .editor-input,
.editor-list-table-cell .editor-field .form-input,
.editor-list-table-cell .editor-field .form-select{
  min-height:38px;
}

/* Wide screens: the sticky column header names every cell, so per-field
   captions are hidden to avoid duplicate labels. */
.editor-list-table .editor-nested-label{display:none;}
.editor-list-table-del{justify-self:end;}

/* Phones: the header row does not fit and is hidden, and each row stacks
   into a card. Without captions bare inputs (e.g. drop quantity / chance)
   are indistinguishable, so every control gets its label back and the slot
   number moves into a compact card header next to the delete button. */
@media (max-width:700px){
  .editor-list-table-header{display:none;}
  .editor-list-table-row{
    grid-template-columns:minmax(0,1fr) auto;
    column-gap:10px;
    row-gap:8px;
    align-items:center;
    padding:12px;
    background:var(--editor-surface-2);
  }
  .editor-list-table-idx{
    display:block;
    grid-column:1;
    grid-row:1;
    font-size:11px;
    font-weight:700;
    letter-spacing:.06em;
    text-transform:uppercase;
  }
  .editor-list-table-del{
    grid-column:2;
    grid-row:1;
    justify-self:end;
  }
  .editor-list-table-cell{grid-column:1 / -1;}
  .editor-list-table .editor-nested-label{display:block;}
}

/* -------------------------------------------------------------
   Sidebar list polish
------------------------------------------------------------- */
.editor-sidebar-list{
  border:1px solid var(--editor-line);
  background:var(--editor-soft-bg);
  border-radius:var(--editor-radius-md);
  overflow:auto;
  max-height:min(72vh, 980px);
}

.editor-sidebar-list > * + *{
  border-top:1px solid transparent;
}

.editor-search{position:relative;}
.editor-search i{
  position:absolute;
  left:12px;
  top:50%;
  transform:translateY(-50%);
  color:var(--editor-text-muted);
  font-size:12px;
  pointer-events:none;
}
/* Match the theme's two-class specificity so its padding shorthand cannot
   cover the icon, regardless of stylesheet load order. */
.editor-search input,
.editor-theme .editor-search input{padding-left:34px;min-width:0;}

/* -------------------------------------------------------------
   Unsaved changes pill
------------------------------------------------------------- */
.editor-dirty-pill{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 10px;
  border-radius:999px;
  font-size:var(--editor-text-xs);
  font-weight:600;
  letter-spacing:0;
  color:var(--editor-warning);
  background:color-mix(in srgb, var(--editor-warning) 12%, transparent);
  border:1px solid color-mix(in srgb, var(--editor-warning) 30%, transparent);
  box-shadow:none;
}

.editor-dirty-pill::before{
  content:"\f071";
  font-family:"Font Awesome 6 Free";
  font-weight:900;
  font-size:10px;
  line-height:1;
  color:currentColor;
}

.editor-dirty-pill.hidden{display:none;}

/* -------------------------------------------------------------
   Task / dialog items
------------------------------------------------------------- */
.editor-item{
  border:1px solid var(--editor-line);
  border-radius:var(--editor-radius-md);
  padding:10px;
  background:var(--editor-surface-2);
  margin-bottom:8px;
  transition:border-color .16s ease, background-color .16s ease;
}

.editor-item:hover{
  border-color:var(--editor-line-strong);
}

.editor-item.is-selected{
  border-color:var(--editor-secondary);
  border-color:color-mix(in srgb, var(--editor-secondary) 65%, var(--editor-soft-border));
  box-shadow:0 0 0 3px var(--editor-focus-ring);
  box-shadow:0 0 0 3px color-mix(in srgb, var(--editor-secondary) 16%, transparent);
  background:var(--editor-light-bg);
  background:color-mix(in srgb, var(--editor-soft-bg) 75%, var(--editor-secondary) 8%);
}

.editor-item-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

.editor-item-summary{
  font-size:12px;
  color:var(--editor-text-muted);
}

.editor-item-actions{
  display:flex;
  align-items:center;
  gap:6px;
}

.editor-item-body{
  margin-top:8px;
  display:grid;
  gap:8px;
}

.editor-item.is-collapsed .editor-item-body{display:none;}

.editor-item-body label{
  font-size:12px;
  color:var(--editor-text-muted);
}

.editor-item-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(180px, 1fr));
  gap:8px;
}

.editor-item-handle{
  cursor:grab;
  color:var(--editor-text-muted);
  user-select:none;
  touch-action:none;
  border-radius:var(--editor-radius-sm);
  padding:0 2px;
}

.editor-item-handle:hover{
  color:var(--editor-text);
}

.editor-item-handle:focus-visible{
  outline:2px solid var(--editor-focus-ring);
  outline-offset:2px;
}

/* Реплика, которую сейчас тащат: приподнята над списком, остальные на месте. */
.editor-item.is-dragging{
  position:relative;
  z-index:2;
  cursor:grabbing;
  border-color:var(--editor-secondary);
  border-color:color-mix(in srgb, var(--editor-secondary) 65%, var(--editor-soft-border));
  box-shadow:var(--editor-shadow-md);
  background:var(--editor-light-bg);
}

body.is-dialog-dragging,
body.is-dialog-dragging *{
  cursor:grabbing !important;
  user-select:none;
}

/* ── Диалог: панель форматов, чипы подстановок и выбор записи ─────────────
   Реплика — это текст с подстановками <bot_12>, <item_31>, <world_3>,
   <player>, <time>, <here>, <eidolon>. Панель над полем вставляет их, чипы
   под полем показывают, что уже вставлено, и позволяют заменить запись. */

.dlg-line{
  display:grid;
  gap:6px;
  min-width:0;
}

.dlg-toolbar{
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:2px;
  padding:3px;
  border:1px solid var(--editor-soft-border);
  border-radius:10px;
  background:var(--editor-soft-bg);
}

.dlg-toolbar-btn{
  display:inline-flex;
  align-items:center;
  gap:5px;
  height:26px;
  padding:0 8px;
  border:1px solid transparent;
  border-radius:8px;
  background:transparent;
  color:var(--editor-text-muted);
  font-size:12px;
  line-height:1;
  white-space:nowrap;
  cursor:pointer;
  transition:background .14s ease, border-color .14s ease, color .14s ease;
}

.dlg-toolbar-btn i{font-size:11px;}
.dlg-toolbar-btn code{font-size:11px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;}
.dlg-toolbar-btn:hover{background:var(--editor-soft-bg-strong);border-color:var(--editor-soft-border);color:var(--editor-text);}
.dlg-toolbar-btn:focus-visible{outline:2px solid var(--editor-focus-ring);outline-offset:1px;}

.dlg-toolbar-sep{
  width:1px;
  height:16px;
  margin:0 3px;
  background:var(--editor-soft-border);
}

.dlg-counter{
  margin-left:auto;
  padding:0 4px;
  font-size:11px;
  font-variant-numeric:tabular-nums;
  color:var(--editor-text-muted);
}

.dlg-counter.is-over{color:#f87171;font-weight:600;}

/* Реплика — компактное многострочное поле: 104px из общей темы здесь лишние. */
.dlg-line textarea{
  min-height:58px;
  resize:vertical;
}

.dlg-tokens{
  display:flex;
  flex-wrap:wrap;
  gap:4px;
}

.dlg-tokens:empty{display:none;}

.dlg-token{
  display:inline-flex;
  align-items:center;
  max-width:100%;
  border:1px solid var(--editor-tag-border);
  border-radius:999px;
  background:var(--editor-tag-bg);
  color:var(--editor-text);
  font-size:11px;
  line-height:1;
}

.dlg-token > i{
  padding:0 2px 0 8px;
  opacity:.75;
}

.dlg-token.is-invalid{
  border-color:rgba(248,113,113,.55);
  background:rgba(248,113,113,.12);
  color:#fca5a5;
}

.dlg-token-label{
  max-width:16rem;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.dlg-token-code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;}
.dlg-token-id{opacity:.55;font-variant-numeric:tabular-nums;}

.dlg-token-main{
  display:inline-flex;
  align-items:center;
  gap:5px;
  max-width:100%;
  padding:4px 8px;
  border:0;
  border-radius:999px;
  background:transparent;
  color:inherit;
  font:inherit;
  cursor:pointer;
}

.dlg-token-main:hover{background:var(--editor-tag-hover-bg);}
.dlg-token-main:focus-visible{outline:2px solid var(--editor-focus-ring);outline-offset:-1px;}

.dlg-token-x{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:22px;
  align-self:stretch;
  padding:4px 6px 4px 2px;
  border:0;
  border-radius:0 999px 999px 0;
  background:transparent;
  color:inherit;
  opacity:.65;
  cursor:pointer;
}

.dlg-token-x:hover{opacity:1;background:var(--editor-tag-hover-bg);}
.dlg-token-x:focus-visible{outline:2px solid var(--editor-focus-ring);outline-offset:-1px;}

/* Всплывающий список записей: вынесен в body и позиционируется от кнопки,
   поэтому его не обрезают прокручиваемые панели редактора. */
.dlg-picker{
  position:fixed;
  z-index:420;
  display:flex;
  flex-direction:column;
  max-height:min(60dvh,380px);
  overflow:hidden;
  border:1px solid var(--editor-soft-border-strong);
  border-radius:14px;
  background:var(--editor-surface);
  box-shadow:var(--editor-dropdown-shadow);
}

.dlg-picker-head{
  display:flex;
  align-items:center;
  gap:8px;
  padding:8px 10px;
  border-bottom:1px solid var(--editor-soft-border);
  color:var(--editor-text-muted);
}

.dlg-picker-search{
  flex:1 1 auto;
  min-width:0;
  height:28px;
  border:0;
  background:transparent;
  color:var(--editor-text);
  font-size:13px;
  outline:none;
}

.dlg-picker-list{
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  gap:1px;
  overflow:auto;
  padding:4px;
}

.dlg-picker-option{
  display:flex;
  align-items:center;
  gap:8px;
  width:100%;
  padding:6px 8px;
  border:1px solid transparent;
  border-radius:9px;
  background:transparent;
  color:var(--editor-text);
  font-size:12px;
  text-align:left;
  cursor:pointer;
}

.dlg-picker-option:hover,
.dlg-picker-option.is-active{background:var(--editor-soft-bg-strong);}

.dlg-picker-option.is-current{
  border-color:color-mix(in srgb, var(--editor-primary) 45%, transparent);
}

.dlg-picker-id{
  min-width:44px;
  color:var(--editor-text-muted);
  font-variant-numeric:tabular-nums;
}

.dlg-picker-label{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.dlg-picker-foot{
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 8px;
  border-top:1px solid var(--editor-soft-border);
}

.dlg-picker-foot:empty{display:none;}

.dlg-picker-remove{
  display:inline-flex;
  align-items:center;
  gap:6px;
  height:28px;
  padding:0 10px;
  border:1px solid rgba(248,113,113,.35);
  border-radius:9px;
  background:transparent;
  color:#f87171;
  font-size:12px;
  cursor:pointer;
}

.dlg-picker-remove:hover{background:rgba(248,113,113,.12);}

.editor-item-subgroup{
  border:1px dashed var(--editor-soft-border-strong);
  border-radius:12px;
  padding:8px;
  background:var(--editor-light-bg);
}

/* -------------------------------------------------------------
   Task editor sections
------------------------------------------------------------- */
.editor-task-section{
  border:1px solid var(--editor-line);
  border-radius:var(--editor-radius-md);
  background:var(--editor-soft-bg);
  margin-bottom:10px;
  overflow:hidden;
}

.editor-task-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:10px 12px;
  cursor:pointer;
  background:var(--editor-light-bg);
}

.editor-task-header h4{
  margin:0;
  font-size:13px;
  font-weight:700;
}

.editor-task-content{
  padding:12px;
  display:none;
}

.editor-task-content.is-open{display:block;}

/* -------------------------------------------------------------
   Productivity modes & viewport-docked desktop split
------------------------------------------------------------- */
body.editor-compact{
  --editor-page-pad: 12px;
  --editor-card-pad: 12px;
  --editor-fields-gap: 10px;
  --editor-control-h: 36px;
}

body.editor-compact .editor-sticky-toolbar{padding:10px;}
body.editor-compact .editor-row{padding:7px 9px;}

@media (min-width:1101px){
  /* Полноэкранный сплит для двухколоночных редакторов: шапка закреплена,
     список слева и форма справа прокручиваются независимо друг от друга. */
  .editor-page:has(> .editor-shell--docked){
    display:flex;
    flex-direction:column;
    height:100vh;
    height:100dvh;
    overflow:hidden;
    padding-bottom:14px;
  }

  .editor-page:has(> .editor-shell--docked) > .editor-page-header{
    flex:0 0 auto;
    z-index:45;
    padding-bottom:12px;
  }

  .editor-page:has(> .editor-shell--docked) > .editor-shell--docked{
    flex:1 1 auto;
    min-height:0;
    margin-top:12px;
    align-items:stretch;
  }

  .editor-shell--docked > .editor-dock-sidebar{
    position:relative;
    top:0;
    height:100%;
    min-height:0;
    display:flex;
    flex-direction:column;
    overflow:hidden;
  }

  .editor-shell--docked > .editor-dock-sidebar > .editor-dock-pad{
    flex:1 1 auto;
    min-height:0;
    display:flex;
    flex-direction:column;
    overflow:hidden;
  }

  .editor-shell--docked > .editor-dock-sidebar :is(.editor-sidebar-list, .editor-list-scroll, .quest-tree-surface){
    flex:1 1 auto;
    min-height:0;
    max-height:none !important;
    overflow-y:auto;
  }

  .editor-shell--docked > .editor-dock-main{
    height:100%;
    min-height:0;
    overflow-y:auto;
    overflow-x:hidden;
    scrollbar-gutter:stable;
  }

  .editor-shell--docked > .editor-dock-main .editor-sticky-toolbar{
    top:0;
  }

  html.editor-guest-mode .editor-shell--docked > .editor-dock-main > .editor-dock-pad{
    padding-bottom:64px;
  }

  /* Режим фокуса: скрывает боковой список, отдавая всю ширину форме. */
  body.editor-focus .editor-shell--docked{
    grid-template-columns:minmax(0, 1fr);
  }

  body.editor-focus .editor-shell--docked > .editor-dock-sidebar{
    display:none;
  }

  body.editor-focus .editor-shell--docked > .editor-dock-main{
    border-radius:var(--editor-card-radius);
  }
}

body.editor-focus .editor-page-sub,
body.editor-focus .editor-sidebar-meta{
  opacity:.78;
}

@media (max-width:1100px){
  body.editor-focus .editor-shell{grid-template-columns:1fr;}
  .editor-dock-sidebar :is(.editor-list-scroll, .quest-tree-surface){
    max-height:min(46vh, 420px);
    max-height:min(46dvh, 420px);
  }
}

/* -------------------------------------------------------------
   Form section dividers & destructive button affordances
------------------------------------------------------------- */
.editor-form-section-divider{
  grid-column:1 / -1;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 0 6px;
  margin-top:4px;
  border-bottom:1px solid var(--editor-line);
}

.editor-form-section-divider:first-child{
  padding-top:0;
  margin-top:0;
}

.editor-form-section-heading{
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-size:var(--editor-text-sm);
  font-weight:700;
  letter-spacing:.04em;
  text-transform:uppercase;
  color:var(--editor-text);
}

.editor-form-section-heading > i{
  color:var(--editor-accent);
  font-size:12px;
}

.editor-form-section-sub{
  font-size:var(--editor-text-xs);
  color:var(--editor-text-muted);
}

.editor-field--span-all{
  grid-column:1 / -1;
}

/* Кнопки удаления в едином тулбаре получают явный опасный ховер, даже если
   в разметке они вторичные — чтобы их нельзя было спутать с «Отменить». */
.editor-btn-secondary:is([data-editor-role="delete"], [data-action="delete"], #btn-delete):not(:disabled):hover{
  color:var(--editor-danger);
  border-color:color-mix(in srgb, var(--editor-danger) 45%, transparent);
  background:color-mix(in srgb, var(--editor-danger) 10%, var(--editor-button-secondary-bg));
}

/* Индикатор активного режима (компакт / фокус) на кнопке «Вид» */
.editor-tools-btn[data-active-modes="1"]{
  border-color:color-mix(in srgb, var(--editor-primary) 48%, transparent);
  background:color-mix(in srgb, var(--editor-primary) 12%, transparent);
  color:var(--editor-text);
}

.editor-tools-dot{
  width:7px;
  height:7px;
  border-radius:999px;
  background:var(--editor-primary);
  display:none;
}

.editor-tools-btn[data-active-modes="1"] .editor-tools-dot{
  display:inline-block;
}

/* -------------------------------------------------------------
   Extra responsive tuning
------------------------------------------------------------- */
@media (max-width:640px){
  .editor-page{
    padding:12px;
  }

  .editor-page-title::before{
    width:30px;
    height:30px;
    flex-basis:30px;
  }

  .editor-panel-card,
  .editor-dock-pad{
    padding:12px;
  }
}

/* -------------------------------------------------------------
   Guest accounts: local (not yet applied) changes
   A guest never writes to the DB, so every record it touched must
   be visibly marked as "draft" or "in a change request".
------------------------------------------------------------- */
.guest-row-badge{
  display:inline-flex;
  align-items:center;
  gap:4px;
  flex:0 0 auto;
  padding:1px 7px;
  border-radius:999px;
  font-size:10.5px;
  font-weight:600;
  line-height:1.6;
  white-space:nowrap;
  border:1px solid var(--editor-soft-border-strong);
}
.guest-row-badge i{font-size:9.5px;}
.guest-row-badge.is-draft{
  color:var(--editor-warning,#ffc27f);
  border-color:color-mix(in srgb,var(--editor-warning,#ffc27f) 45%,transparent);
  background:color-mix(in srgb,var(--editor-warning,#ffc27f) 12%,transparent);
}
.guest-row-badge.is-submitted{
  color:var(--editor-primary,#6366f1);
  border-color:color-mix(in srgb,var(--editor-primary,#6366f1) 45%,transparent);
  background:color-mix(in srgb,var(--editor-primary,#6366f1) 12%,transparent);
}

.guest-row-hint{
  display:flex;
  align-items:flex-start;
  gap:10px;
  margin-bottom:12px;
  padding:10px 12px;
  border-radius:12px;
  font-size:13px;
  line-height:1.45;
  border:1px solid color-mix(in srgb,var(--editor-warning,#ffc27f) 45%,transparent);
  background:color-mix(in srgb,var(--editor-warning,#ffc27f) 8%,transparent);
  color:var(--editor-text);
}
.guest-row-hint i{margin-top:3px;color:var(--editor-warning,#ffc27f);}
.guest-row-hint.is-submitted{
  border-color:color-mix(in srgb,var(--editor-primary,#6366f1) 45%,transparent);
  background:color-mix(in srgb,var(--editor-primary,#6366f1) 8%,transparent);
}
.guest-row-hint.is-submitted i{color:var(--editor-primary,#6366f1);}
.guest-row-hint-fields{margin-top:4px;font-size:11.5px;color:var(--editor-text-muted);}
.guest-row-hint-fields code{
  padding:0 5px;
  border-radius:5px;
  background:var(--editor-soft-bg-strong);
  font-size:11px;
}

/* Field-level markers of the guest's own values (form view) */
[data-field-path].guest-field-changed{
  position:relative;
  border-radius:10px;
  box-shadow:0 0 0 1px color-mix(in srgb,var(--editor-warning,#ffc27f) 45%,transparent);
  background:color-mix(in srgb,var(--editor-warning,#ffc27f) 5%,transparent);
}
[data-field-path].guest-field-changed.is-submitted{
  box-shadow:0 0 0 1px color-mix(in srgb,var(--editor-primary,#6366f1) 45%,transparent);
  background:color-mix(in srgb,var(--editor-primary,#6366f1) 5%,transparent);
}
[data-field-path].guest-field-changed::after{
  content:'изм.';
  position:absolute;
  top:-7px;
  right:8px;
  padding:0 5px;
  border-radius:999px;
  font-size:9.5px;
  font-weight:700;
  line-height:1.6;
  letter-spacing:.02em;
  color:var(--editor-warning,#ffc27f);
  background:var(--editor-surface,#121821);
  border:1px solid color-mix(in srgb,var(--editor-warning,#ffc27f) 45%,transparent);
}
[data-field-path].guest-field-changed.is-submitted::after{
  content:'в запросе';
  color:var(--editor-primary,#6366f1);
  border-color:color-mix(in srgb,var(--editor-primary,#6366f1) 45%,transparent);
}

/* Маленькая кнопка «вернуть как в базе» рядом с меткой «изм.».

   Метка — это ::after у самого поля, поэтому кнопка живёт отдельным узлом:
   так у неё есть фокус с клавиатуры и всплывающая подсказка. Метка при этом
   сдвигается влево, чтобы элементы не накладывались друг на друга. */
[data-field-path].guest-field-revertable::after{
  right:30px;
}
[data-field-path] > .guest-field-revert{
  position:absolute;
  top:-9px;
  right:6px;
  z-index:2;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:19px;
  height:19px;
  padding:0;
  border-radius:999px;
  border:1px solid color-mix(in srgb,var(--editor-warning,#ffc27f) 55%,transparent);
  background:var(--editor-surface,#121821);
  color:var(--editor-warning,#ffc27f);
  font-size:9px;
  line-height:1;
  cursor:pointer;
  transition:background .15s ease,color .15s ease,border-color .15s ease;
}
[data-field-path] > .guest-field-revert:hover{
  background:var(--editor-warning,#ffc27f);
  border-color:var(--editor-warning,#ffc27f);
  color:#0b0f14;
}
[data-field-path] > .guest-field-revert:focus-visible{
  outline:2px solid var(--editor-primary,#6366f1);
  outline-offset:2px;
}
@media (prefers-reduced-motion:reduce){
  [data-field-path] > .guest-field-revert{transition:none;}
}

/* Подсветка поля, к которому вела ссылка «открыть запись». */
[data-field-path].field-link-target{
  border-radius:10px;
  box-shadow:0 0 0 2px var(--editor-primary,#6366f1),
    0 0 0 6px color-mix(in srgb,var(--editor-primary,#6366f1) 12%,transparent);
  animation:fieldLinkPulse 1.6s ease-out 1;
}
@keyframes fieldLinkPulse{
  0%,100%{filter:none;}
  45%{filter:brightness(1.16);}
}
@media (prefers-reduced-motion:reduce){
  [data-field-path].field-link-target{animation:none;}
}

/* Shared record markers also cover custom editors and the quest tree. */
[data-id].guest-shared-row-changed,
[data-id].request-row-changed{
  position:relative;
  scroll-margin:80px;
  box-shadow:inset 3px 0 0 var(--editor-warning,#ffc27f);
}
[data-id].guest-shared-row-changed.is-submitted,
[data-id].request-row-changed{
  box-shadow:inset 3px 0 0 var(--editor-primary,#6366f1);
}
[data-id].guest-shared-row-editing:not(.guest-shared-row-changed){
  box-shadow:inset 3px 0 0 var(--editor-warning,#ffc27f);
}
[data-id].request-row-target{
  outline:2px solid var(--editor-primary,#6366f1) !important;
  outline-offset:-2px;
  background:color-mix(in srgb,var(--editor-primary,#6366f1) 10%,transparent) !important;
}
.change-row-marker{
  position:absolute;
  right:5px;
  bottom:5px;
  z-index:3;
  display:inline-flex;
  align-items:center;
  gap:4px;
  max-width:calc(100% - 10px);
  padding:1px 6px;
  border:1px solid color-mix(in srgb,var(--editor-warning,#ffc27f) 45%,transparent);
  border-radius:999px;
  color:var(--editor-warning,#ffc27f);
  background:var(--editor-surface,#121821);
  font-size:9.5px;
  font-weight:700;
  line-height:1.55;
  pointer-events:none;
}
.change-row-marker.is-submitted{
  color:var(--editor-primary,#6366f1);
  border-color:color-mix(in srgb,var(--editor-primary,#6366f1) 45%,transparent);
}

/* A guest sees a marker already while typing, before the draft is saved. */
[data-field-path].guest-field-editing:not(.guest-field-changed){
  position:relative;
  border-radius:10px;
  box-shadow:0 0 0 1px color-mix(in srgb,var(--editor-warning,#ffc27f) 55%,transparent);
  background:color-mix(in srgb,var(--editor-warning,#ffc27f) 7%,transparent);
}
[data-field-path].guest-field-editing:not(.guest-field-changed)::after{
  content:'ввод';
  position:absolute;
  top:-7px;
  right:8px;
  padding:0 5px;
  border:1px solid color-mix(in srgb,var(--editor-warning,#ffc27f) 55%,transparent);
  border-radius:999px;
  color:var(--editor-warning,#ffc27f);
  background:var(--editor-surface,#121821);
  font-size:9.5px;
  font-weight:700;
  line-height:1.6;
}

/* Request preview: exact field target plus all sibling changes in the form. */
[data-field-path].request-field-changed{
  position:relative;
  border-radius:10px;
  box-shadow:0 0 0 1px color-mix(in srgb,var(--editor-primary,#6366f1) 50%,transparent);
  background:color-mix(in srgb,var(--editor-primary,#6366f1) 6%,transparent);
  scroll-margin:100px;
}
[data-field-path].request-field-changed::after{
  content:'запрос';
  position:absolute;
  z-index:4;
  top:-7px;
  right:8px;
  padding:0 5px;
  border:1px solid color-mix(in srgb,var(--editor-primary,#6366f1) 50%,transparent);
  border-radius:999px;
  color:var(--editor-primary,#6366f1);
  background:var(--editor-surface,#121821);
  font-size:9.5px;
  font-weight:700;
  line-height:1.6;
}
[data-field-path].request-field-target{
  box-shadow:0 0 0 2px var(--editor-primary,#6366f1),0 0 0 6px color-mix(in srgb,var(--editor-primary,#6366f1) 12%,transparent);
  animation:requestTargetPulse 1.8s ease-out 2;
}
@keyframes requestTargetPulse{
  0%,100%{filter:none;}
  45%{filter:brightness(1.18);}
}
.request-preview-banner{
  position:fixed;
  z-index:650;
  left:50%;
  bottom:14px;
  transform:translateX(-50%);
  display:flex;
  align-items:center;
  gap:11px;
  width:max-content;
  max-width:calc(100vw - 28px);
  padding:10px 12px;
  border:1px solid color-mix(in srgb,var(--editor-primary,#6366f1) 45%,transparent);
  border-radius:13px;
  color:var(--editor-text);
  background:color-mix(in srgb,var(--editor-surface,#121821) 96%,transparent);
  box-shadow:var(--editor-shadow-lg,0 12px 36px #0008);
  backdrop-filter:blur(12px);
}
.request-preview-banner > i{color:var(--editor-primary,#6366f1);font-size:17px;}
.request-preview-banner--editing{
  border-color:color-mix(in srgb,var(--editor-warning,#ffc27f) 60%,transparent);
}
.request-preview-banner--editing > i{color:var(--editor-warning,#ffc27f);}
.request-preview-banner-text{display:grid;min-width:0;font-size:12.5px;line-height:1.4;}
.request-preview-banner-text span,.request-preview-banner-text small{color:var(--editor-text-muted);overflow-wrap:anywhere;}
.request-preview-banner-text small{font-size:11px;}
.request-preview-banner-text code{color:var(--editor-primary,#6366f1);}
.request-preview-active input:disabled,
.request-preview-active textarea:disabled,
.request-preview-active select:disabled{opacity:.82;cursor:default;}
@media (max-width:640px){
  .request-preview-banner{align-items:flex-start;flex-wrap:wrap;bottom:8px;padding:9px 10px;}
  .request-preview-banner-text{flex:1;}
  .request-preview-banner > a{margin-left:auto;}
}
@media (prefers-reduced-motion:reduce){
  [data-field-path].request-field-target{animation:none;}
}

/* -------------------------------------------------------------
   Layout primitives (shared by every editor page)

   Всё, что раньше задавалось инлайновыми style="max-height:590px" /
   style="grid-template-columns:..." на страницах, живёт здесь: одна
   точка правки и одинаковое поведение на всех вкладках.
------------------------------------------------------------- */

/* Тело страницы: вертикальный ритм и одинаковая реакция на узкий экран. */
.editor-page-body{
  margin-top:16px;
  display:grid;
  gap:16px;
  align-content:start;
  min-width:0;
}

.editor-page-body > *{min-width:0;}

/* Две равные колонки; до 1100px — одна (планшет/телефон). */
.editor-two-col{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:16px;
  align-items:start;
  min-width:0;
}

.editor-two-col > *{min-width:0;}

@media (max-width:1100px){
  .editor-two-col{grid-template-columns:minmax(0, 1fr);}
}

/* Прокручиваемый список: заменяет инлайновый max-height. */
.editor-list-scroll{
  overflow:auto;
  max-height:min(590px, 62vh);
  max-height:min(590px, 62dvh);
  border:1px solid var(--editor-line);
  border-radius:var(--editor-radius-md);
  background:var(--editor-surface);
  -webkit-overflow-scrolling:touch;
  overscroll-behavior:contain;
}

.editor-list-scroll--tall{max-height:min(900px, 72vh);max-height:min(900px, 72dvh);}
.editor-list-scroll--short{max-height:min(320px, 42vh);max-height:min(320px, 42dvh);}

/* Компактные кнопки одного вида (было height:32px / 28px в style). */
.editor-btn--sm{height:32px;padding:0 12px;font-size:12.5px;}
.editor-btn--xs{height:28px;padding:0 9px;font-size:12px;}

/* Таблицы: на узком экране прокручиваются, а не разъезжаются. */
.editor-table-wrap{
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
  border:1px solid var(--editor-line);
  border-radius:var(--editor-radius-md);
  background:var(--editor-surface);
}

.editor-table-wrap > table,
.editor-list-scroll > table{
  width:100%;
  border-collapse:collapse;
  min-width:var(--editor-table-min, 480px);
}

.editor-table-wrap :is(th, td),
.editor-list-scroll :is(th, td){
  padding:9px 12px;
  text-align:left;
  font-size:var(--editor-text-md);
  border-bottom:1px solid var(--editor-line);
  vertical-align:top;
}

.editor-table-wrap tbody tr:hover,
.editor-list-scroll tbody tr:hover{
  background:var(--editor-row-hover-bg);
}

.editor-table-wrap thead th,
.editor-list-scroll thead th{
  position:sticky;
  top:0;
  z-index:1;
  font-size:var(--editor-text-xs);
  font-weight:700;
  letter-spacing:.06em;
  text-transform:uppercase;
  color:var(--editor-text-muted);
  background:var(--editor-surface);
  white-space:nowrap;
}

.editor-table-wrap tbody tr:last-child :is(th, td),
.editor-list-scroll tbody tr:last-child :is(th, td){border-bottom:0;}

/* Внутри карточки таблица не рисует вторую рамку. */
.editor-panel-card > .editor-table-wrap,
.editor-panel-card > .editor-list-scroll{border-color:var(--editor-soft-border);}

/* Секция на всю ширину внутри .editor-two-col. */
.editor-span-all{grid-column:1 / -1;}

/* Сайдбар на планшете/телефоне встаёт над редактором: ограничиваем высоту
   списка, иначе до формы нужно листать несколько экранов. */
@media (max-width:1100px){
  .editor-sidebar-list{max-height:min(46vh, 420px);max-height:min(46dvh, 420px);}
}

/* На телефоне списки не растягивают страницу на несколько экранов. */
@media (max-width:640px){
  .editor-list-scroll{max-height:min(460px, 52vh);max-height:min(460px, 52dvh);}
  .editor-list-scroll--tall{max-height:min(560px, 60vh);max-height:min(560px, 60dvh);}
  .editor-list-scroll--short{max-height:min(280px, 38vh);max-height:min(280px, 38dvh);}
  .editor-page-body{gap:12px;margin-top:12px;}
  .editor-two-col{gap:12px;}
  .editor-btn--sm{height:34px;}
}

@media (max-width:520px){
  .editor-page{padding:12px;}
  .editor-page-title{gap:10px;}
  .editor-page-title h1{font-size:20px;}
  .editor-page-sub{font-size:12.5px;}
  .editor-page-title::before{
    width:30px;height:30px;flex-basis:30px;font-size:13px;
  }
  .editor-table-wrap > table,
  .editor-list-scroll > table{min-width:var(--editor-table-min, 420px);}
}

/* Очень узкие экраны: шапка переносится, кнопки делят строку поровну. */
@media (max-width:400px){
  .editor-page-header{flex-wrap:wrap;}
  .editor-page-actions{width:100%;justify-content:flex-start;}
  .editor-page-actions .editor-btn{flex:1 1 auto;min-width:0;}
  .editor-page-title{min-width:0;}
}

/* Метки «поле изменено» из гостевого режима — на языке интерфейса. */
:root[lang="en"] [data-field-path].guest-field-changed::after{content:'edited';}
:root[lang="en"] [data-field-path].guest-field-changed.is-submitted::after{content:'in request';}
:root[lang="en"] [data-field-path].request-field-changed::after{content:'request';}
:root[lang="en"] [data-field-path].guest-field-editing:not(.guest-field-changed)::after{content:'editing';}

/* Утилиты ограничения ширины вместо style="max-width:260px" на страницах. */
[data-width="sm"]{max-width:260px;}
[data-width="md"]{max-width:420px;}

@media (max-width:520px){
  [data-width]{max-width:100%;}
}

/* Тона текста: заменяют инлайн-стили цвета в разметке и в строках шаблонов. */
.editor-tone-danger{color:var(--editor-danger);}
.editor-tone-warning{color:var(--editor-warning);}
.editor-tone-success{color:var(--editor-success);}
.editor-tone-accent{color:var(--editor-accent);}

/* -------------------------------------------------------------
   Touch-устройства и длинный текст
------------------------------------------------------------- */

/* Пальцем нужно попадать: на сенсорных экранах цели не меньше 44px. */
@media (pointer:coarse){
  .editor-btn{min-height:44px;}
  .editor-icon-btn{min-width:44px;min-height:44px;}
}

/* Длинные слова (имена таблиц, логины, значения из базы) не рвут вёрстку. */
.editor-page-sub,
.editor-help-text{overflow-wrap:anywhere;}

.editor-page :is(td, th, dd, dt) code,
.editor-page :is(td, th, dd, dt) a{overflow-wrap:anywhere;}

/* Медиа внутри контента не вылезает за карточку (размеры из классов сохраняем). */
.editor-page img,
.editor-page video,
.editor-page canvas{max-width:100%;}

/* Горизонтальная прокрутка вместо «уехавшей» вёрстки: любой блок кода. */
.editor-page pre{overflow-x:auto;max-width:100%;}

/* Строка во всю ширину сетки задачи: позиция X/Y с кнопкой карты не должна
   сжиматься до одной колонки — иначе оси снова «разъезжаются». */
.editor-item-span{grid-column:1/-1;min-width:0;}

/* Related record drill-down: one header, regardless of navigation depth. */
.related-record-control{display:flex;align-items:flex-start;gap:6px;min-width:0;max-width:100%;}
.related-record-control > :first-child{flex:1 1 0;min-width:0;max-width:100%;}
.related-record-link{flex:0 0 auto;min-height:38px;}
.related-record-dialog{
  width:calc(100% - 24px);max-width:1600px;
  height:calc(100vh - 24px);height:calc(100dvh - 24px);max-height:none;
  margin:auto;padding:0;border:1px solid var(--editor-line);border-radius:var(--editor-radius-lg);
  color:var(--editor-text);background:var(--editor-bg);overflow:hidden;
}
.related-record-dialog[open]{display:flex;flex-direction:column;}
.related-record-dialog::backdrop{background:rgb(0 0 0 / .55);}
.related-record-header{display:flex;flex-wrap:wrap;align-items:center;gap:8px 14px;padding:10px 12px;border-bottom:1px solid var(--editor-line);flex-shrink:0;}
.related-record-trail{flex:1 1 160px;min-width:0;overflow-wrap:anywhere;font-size:14px;}
.related-record-hint{color:var(--editor-text-muted);font-size:12px;}
.related-record-dialog > iframe{flex:1 1 0;min-height:0;width:100%;border:0;background:var(--editor-bg);}
.related-record-dialog > iframe[hidden]{display:none;}

@media (max-width:640px){
  /* Avoid iOS zooming the entire editor when focusing a field. */
  .editor-theme :is(input:not([type="checkbox"]):not([type="radio"]),select,textarea){font-size:16px;}
  .editor-page-header{flex-wrap:wrap;gap:12px;}
  .editor-page-actions{flex-wrap:wrap;max-width:100%;}
  .editor-page-actions .editor-btn{white-space:normal;height:auto;min-height:40px;}
  .related-record-dialog{width:100%;max-width:none;height:100vh;height:100dvh;border:0;border-radius:0;}
  .related-record-header{padding:8px max(8px,env(safe-area-inset-right)) 8px max(8px,env(safe-area-inset-left));}
  .related-record-header .editor-btn{min-height:44px;}
  .related-record-hint{display:none;}
  .related-record-trail{font-size:12px;}
}
@media (pointer:coarse){
  .related-record-link{min-width:44px;min-height:44px;}
  .editor-dbcombo-option{min-height:44px;}
}
@media (max-width:640px){
  .editor-sticky-toolbar{flex-wrap:wrap;gap:10px;min-width:0;}
  .editor-sticky-toolbar > :first-child{flex:1 1 100%;min-width:0;overflow-wrap:anywhere;}
  .editor-sticky-toolbar > .editor-page-actions{flex:1 1 100%;justify-content:flex-start;}
  .editor-sticky-toolbar .editor-btn{flex:1 1 auto;}
}
.related-record-list{display:flex;flex-wrap:wrap;gap:6px;margin-top:6px;}

/* -------------------------------------------------------------
   Адаптивная «страховочная сетка» (идёт последней намеренно)
   -------------------------------------------------------------
   Раньше на ≤640px .editor-page-actions превращался в grid
   repeat(auto-fit, minmax(140px, 1fr)): каждая кнопка, поле ввода,
   select и переключатель становились отдельной ячейкой во всю её
   ширину, шапка редактора растягивалась на пол-экрана (см. мобильный
   Scenarios: Delete/JSON/Import/Save — каждый на своей строке), а
   элементы с min-width вылезали за край и налезали друг на друга.
   Ниже — предсказуемый перенос: кнопки делят строку пополам, поля и
   выпадающие списки занимают строку целиком, иконочные кнопки не
   растягиваются. Специфичность .editor-page-header/.editor-sticky-toolbar
   выше одиночных Tailwind-утилит (flex-nowrap и т.п.), которые иначе
   перебивали бы перенос из-за порядка подключения стилей. */
@media (max-width:640px){
  .editor-page-header .editor-page-actions,
  .editor-sticky-toolbar .editor-page-actions,
  .editor-page-actions{
    display:flex;
    flex-wrap:wrap;
    align-items:center;
    justify-content:flex-start;
    width:100%;
    min-width:0;
  }

  .editor-page-actions > *{min-width:0;}

  /* Текстовые кнопки — по две в ряд, подписи не рвутся по словам. */
  .editor-page-actions .editor-btn{
    flex:1 1 calc(50% - 4px);
    justify-content:center;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }

  /* Кнопка только с иконкой (помощь «?», корзина, undo) не должна
     тянуться на полстроки из-за общего правила выше. */
  .editor-page-actions .editor-btn:has(> i:only-child),
  .editor-page-actions .editor-icon-btn{
    flex:0 0 auto;
    justify-content:center;
  }
  .editor-page-actions .editor-btn:has(> i:only-child){min-width:44px;}

  /* Поля в шапке — всегда своей строкой: в ячейке 140px select/поиск
     нечитаемы и именно они создавали горизонтальный перелив. */
  .editor-page-actions :is(input, select, textarea){
    flex:1 1 100%;
    width:auto;
    max-width:100%;
  }
  .editor-page-actions > label{flex:1 1 100%;min-width:0;}

  /* Заголовок страницы: длинное название/подзаголовок переносятся,
     а не выдавливают действия за экран. */
  .editor-page-title{min-width:0;flex:1 1 auto;}
  .editor-page-title h1{overflow-wrap:anywhere;}
  .editor-page-title > i{flex-basis:36px;width:36px;height:36px;}

  /* Окна не выходят за вьюпорт телефона. */
  .editor-modal-content{max-width:calc(100vw - 24px);max-width:calc(100dvw - 24px);}
  .editor-modal-backdrop{padding:12px;}

  /* Любой прямой ребёнок страницы может сжаться: flex/grid-элементы
     по умолчанию имеют min-width:auto и широким содержимым (таблицей,
     длинным словом) раздвигают страницу вбок. */
  .editor-page > *,
  .editor-page-body > *,
  .main-container > *{min-width:0;}
}

/* Совсем узкие экраны: одна кнопка в ряд надёжнее, чем две по 140px. */
@media (max-width:360px){
  .editor-page-actions .editor-btn{flex-basis:100%;}
  .editor-page-actions .editor-btn:has(> i:only-child),
  .editor-page-actions .editor-icon-btn{flex-basis:auto;}
}
