/* =====================================================================
   КОНСТРУКТОР — раскладка редактора. Токены берутся из style.css.
   ===================================================================== */

.ed-body { height: 100dvh; overflow: hidden; }

.ed {
  display: grid;
  height: 100dvh;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: 'top' 'stage' 'sheet' 'rail';
}

/* ---------- Верхняя панель ---------- */
.ed-top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.ed-top .logo__word { font-size: 1.125rem; }
.ed-top .logo__sub { font-size: 0.6875rem; }
.ed-title {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  font: 600 0.9375rem/1 var(--font-mono);
  letter-spacing: -0.02em;
  color: var(--ink-2);
}
.ed-top__actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.ed-top__actions .btn { margin-left: 8px; }
.icon-btn:disabled { color: var(--line-strong); cursor: default; }
.ed-wide { display: none; }

/* ---------- Вкладки инструментов ---------- */
.ed-rail { grid-area: rail; border-top: 1px solid var(--line); background: var(--paper); padding-bottom: env(safe-area-inset-bottom); }
.ed-rail__list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.ed-rail button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 62px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s;
}
.ed-rail button:hover { color: var(--ink); }
.ed-rail button[aria-selected='true'] { color: var(--blue); }
.ed[data-sheet='panels'] .ed-rail button[aria-selected='true'] { background: var(--blue-wash); }
.ed-rail button:focus-visible { outline-offset: -3px; }

/* ---------- Панели (на телефоне — шторка над вкладками) ---------- */
.ed-sheet {
  grid-area: sheet;
  display: none;
  max-height: 46dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 16px 20px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.ed[data-sheet='panels'] .ed-panels,
.ed[data-sheet='side'] .ed-side { display: block; animation: sheet-in 0.3s var(--ease-out); }
@keyframes sheet-in { from { transform: translateY(16px); opacity: 0; } }

.ed-panel__head {
  position: sticky;
  top: -4px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  margin-bottom: 8px;
  background: var(--paper);
}
.ed-h { font: 600 1.0625rem/1.2 var(--font-mono); letter-spacing: -0.02em; }
.ed-label { display: block; margin-bottom: 10px; padding: 0; font-size: 0.875rem; font-weight: 600; }
.ed-muted { font-size: 0.875rem; line-height: 1.5; color: var(--ink-2); }
.ed-group { min-width: 0; margin: 0 0 22px; padding: 0; border: 0; }

.ed-models { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.ed-model .choice__box { width: 100%; height: auto; min-height: 84px; flex-direction: column; gap: 4px; padding: 8px 4px; display: flex; }
.ed-model .icon { width: 40px; height: 40px; stroke-width: 1.25; }
.ed-model__name { font-size: 0.8125rem; }

.ed-colors { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.ed-color { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ed-color__name { font-size: 0.75rem; color: var(--ink-2); }

.ed-fonts { display: grid; gap: 8px; margin-top: 12px; }
.ed-font {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--card);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s;
}
.ed-font:hover { border-color: var(--ink); }
.ed-font__sample { font-size: 1.375rem; line-height: 1.1; }
.ed-font__name { font: 400 0.75rem/1.2 var(--font-sans); color: var(--ink-3); }

.ed-stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.ed-sticker {
  aspect-ratio: 1;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s var(--ease-out);
}
.ed-sticker:hover { border-color: var(--blue); transform: rotate(-3deg); }
.ed-sticker svg { width: 100%; height: 100%; }

.ed-drop {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 28px 16px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 2px;
  background: var(--card);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}
.ed-drop:hover,
.ed-drop.is-drag,
.ed-drop.is-attention { border-color: var(--blue); background: var(--blue-wash); }
.ed-drop:focus-within { outline: 2px solid var(--blue); outline-offset: 3px; }
.ed-drop .icon { color: var(--blue); }
.ed-drop__title { font-weight: 600; }
.ed-drop__note { font-size: 0.8125rem; color: var(--ink-2); }
.ed-tips { display: grid; gap: 8px; margin-top: 16px; font-size: 0.875rem; color: var(--ink-2); }
.ed-tips li { position: relative; padding-left: 16px; }
.ed-tips li::before { content: '—'; position: absolute; left: 0; color: var(--blue); }

.ed-sizes { display: flex; flex-wrap: wrap; gap: 8px; }
.ed-techniques { display: grid; gap: 2px; }
.ed-radio { display: flex; align-items: center; gap: 12px; min-height: 40px; cursor: pointer; font-size: 0.9375rem; }
.ed-radio input { width: 18px; height: 18px; margin: 0; accent-color: var(--blue); }

.ed-order-actions { display: grid; gap: 10px; justify-items: start; margin-top: 8px; }
.ed-order-actions .btn--primary { width: 100%; }

.ed-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--blue);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}
.ed-link:hover { text-decoration: underline; text-underline-offset: 0.2em; }
.ed-link--danger { color: var(--danger); }

/* ---------- Сцена ---------- */
.ed-stage {
  grid-area: stage;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 0;
  padding: 10px 12px 8px;
}
.ed-stage__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; }

.segmented { display: inline-flex; border: 1px solid var(--ink); border-radius: 2px; }
.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  background: none;
  font: 500 0.875rem/1 var(--font-mono);
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--ink); }
.segmented [aria-checked='true'],
.segmented [aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.segmented__count:not(:empty) { min-width: 18px; padding: 2px 4px; border-radius: 9px; background: var(--blue); color: #fff; font-size: 0.6875rem; text-align: center; }
.segmented--small button { min-height: 36px; padding: 0 12px; font-family: var(--font-sans); font-size: 0.8125rem; }

.ed-layers-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--card);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.ed-canvas-host { flex: 1 1 auto; display: grid; place-items: center; width: 100%; min-height: 0; border-radius: 2px; container-type: size; transition: background-color 0.2s; }
.ed-canvas-host.is-drag { background: var(--blue-wash); }
.ed-canvas {
  position: relative;
  width: max(240px, min(100cqw, 100cqh));
  height: max(240px, min(100cqw, 100cqh));
  background: #f1f1ee url('../img/decor/grain.png');
  box-shadow: var(--shadow-print);
}
.ed-canvas .canvas-container { position: absolute !important; inset: 0; }

.ed-empty {
  position: absolute;
  left: 50%;
  top: 42%;
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(86%, 280px);
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}
.ed-empty p { font: 500 0.8125rem/1.3 var(--font-mono); color: var(--ink-2); }
.ed-empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; pointer-events: auto; }
.ed-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--card);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.ed-chip:hover { background: var(--ink); color: var(--paper); }

.ed-loading { position: absolute; inset: 0; display: grid; place-items: center; font: 500 0.875rem var(--font-mono); color: var(--ink-2); }
.ed-loading[hidden] { display: none; }

.ed-product { font: 400 0.8125rem/1.3 var(--font-mono); color: var(--ink-2); text-align: center; }
.ed-hint {
  max-width: 560px;
  padding: 8px 12px;
  border: 1px solid #e8c766;
  border-radius: 2px;
  background: #fff4d6;
  color: #4d3a00;
  font-size: 0.8125rem;
  line-height: 1.4;
}

.ed-context { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); width: 100%; border: 1px solid var(--line); background: var(--card); }
.ed-context[hidden] { display: none; }
.ed-context button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  padding: 6px 2px;
  border: 0;
  background: none;
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
}
.ed-context button + button { border-left: 1px solid var(--line); }
.ed-context button:last-child { color: var(--danger); }
.ed-context .icon { width: 20px; height: 20px; }

/* ---------- Свойства и слои ---------- */
.ed-props { display: grid; gap: 4px; margin-bottom: 24px; }
.ed-field { display: grid; margin-bottom: 18px; }
.ed-field textarea {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--card);
  font-size: 1rem;
  line-height: 1.4;
  resize: vertical;
}
.ed-field textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 1px var(--blue); }
.ed-field .select select { width: 100%; }

.ed-ink { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.ed-ink .choice--color .choice__box { width: 40px; min-height: 40px; }
.ed-ink .swatch { width: 26px; height: 26px; }
.ed-custom-color { position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.ed-custom-color span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: conic-gradient(#d7262e, #f2c230, #2f8f4e, #1a40c0, #8a3ab9, #d7262e);
  color: #fff;
}
.ed-custom-color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.ed-custom-color:focus-within { outline: 2px solid var(--blue); outline-offset: 2px; }

.ed-quality { font-size: 0.9375rem; }
.ed-quality span { color: var(--ink-3); }
.ed-quality[data-level='low'] b { color: var(--danger); }

.ed-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.ed-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--card);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s;
}
.ed-action:hover { border-color: var(--ink); }
.ed-action--danger { color: var(--danger); }

.ed-layers { padding-top: 18px; border-top: 1px solid var(--line); }
.ed-layer-list { display: grid; gap: 2px; margin-top: 12px; }
.ed-layer { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; border-radius: 2px; }
.ed-layer.is-selected { background: var(--blue-wash); }
.ed-layer .icon-btn { width: 36px; height: 40px; }
.ed-layer__main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: none;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}
.ed-layer__main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-layer.is-selected .ed-layer__main { color: var(--blue); font-weight: 600; }

/* ---------- Отправка ---------- */
.send-dialog {
  width: min(960px, 100% - 32px);
  max-width: none;
  max-height: min(90dvh, 760px);
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 80px -24px rgb(18 18 18 / 0.5);
}
.send-dialog[open] { display: flex; flex-direction: column; animation: menu-in 0.3s var(--ease-out); }
.send-dialog::backdrop { background: rgb(18 18 18 / 0.45); }
.send-dialog__head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 24px; border-bottom: 1px solid var(--line); }
.send-dialog__body { display: grid; gap: 24px; padding: 24px; overflow-y: auto; }
.send-dialog__preview { display: grid; place-items: center; min-height: 180px; padding: 10px; background: var(--card); box-shadow: var(--shadow-print); }
.send-dialog__preview img { width: 100%; height: auto; }
.send-code { margin-bottom: 16px; font-size: 0.9375rem; color: var(--ink-2); }
.send-code b { margin-left: 6px; font: 600 1.125rem var(--font-mono); color: var(--ink); letter-spacing: 0.04em; }
[data-send-share] { display: grid; gap: 8px; margin-bottom: 8px; }
[data-send-share][hidden] { display: none; }
.send-or { margin-top: 8px; font-size: 0.8125rem; color: var(--ink-3); }
.send-steps { display: grid; gap: 18px; margin-bottom: 16px; }
.send-steps li { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; }
.send-steps p { margin-bottom: 10px; font-size: 0.9375rem; }
.send-steps__n { display: grid; place-items: center; width: 28px; height: 28px; border: 1.5px solid var(--blue); border-radius: 50%; font: 600 0.8125rem var(--font-mono); color: var(--blue); }
.send-links { display: flex; flex-wrap: wrap; gap: 8px; }
.send-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.2s, color 0.2s;
}
.send-link:hover { background: var(--ink); color: var(--paper); }
.send-link .icon { width: 20px; height: 20px; }
.send-text { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.send-text summary { min-height: 40px; display: flex; align-items: center; font-size: 0.875rem; font-weight: 600; cursor: pointer; }
.send-text pre {
  max-height: 180px;
  margin: 8px 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--card);
  font: 400 0.75rem/1.5 var(--font-mono);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Подсказка внизу ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  width: max-content;
  max-width: min(92vw, 520px);
  padding: 12px 16px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9375rem;
  line-height: 1.4;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.35s var(--ease-out);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
@media (max-width: 1099px) {
  /* на телефоне подсказка под верхней панелью: не закрывает вещь, подпись и кнопки внизу */
  .toast { top: calc(66px + env(safe-area-inset-top)); bottom: auto; transform: translate(-50%, -12px); }
}
.toast button {
  flex: none;
  min-height: 36px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: #a9bbff;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.ed-noscript { position: fixed; inset: auto 16px 16px; padding: 16px; background: var(--ink); color: var(--paper); }

/* ---------- Широкий экран ---------- */
@media (min-width: 600px) {
  .ed-wide { display: inline; }
  .ed-top { padding: 0 16px 0 24px; gap: 16px; }
  .send-dialog__body { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
}

@media (max-width: 1099px) {
  .ed[data-sheet] .ed-context { display: none; }
}

@media (min-width: 1100px) {
  .ed {
    grid-template-columns: 92px 300px minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'top top top top' 'rail panels stage side';
  }
  .ed-top { min-height: 64px; }
  .ed-rail { border-top: 0; border-right: 1px solid var(--line); padding: 12px 0 0; }
  .ed-rail__list { grid-template-columns: 1fr; gap: 2px; }
  .ed-rail button { min-height: 76px; font-size: 0.8125rem; }
  .ed-rail button[aria-selected='true'] { background: var(--blue-wash); }

  .ed-sheet {
    display: block;
    max-height: none;
    padding: 8px 24px 32px;
    border-top: 0;
    animation: none !important;
  }
  .ed-panels { grid-area: panels; border-right: 1px solid var(--line); }
  .ed-side { grid-area: side; border-left: 1px solid var(--line); }
  .ed-panel__head { top: -8px; }
  .ed-sheet-close,
  .ed-layers-btn,
  .ed-context { display: none !important; }

  .ed-stage { padding: 20px 28px 18px; gap: 12px; }
  .ed-stage__bar { justify-content: center; }
  .toast,
  body:has(.ed.has-selection) .toast { bottom: 72px; }
}

@media (max-width: 519px) {
  .ed-title { display: none; }
  .ed-top { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .ed-sheet { animation: none !important; }
}
