:root {
  --bg: #1c1f26;
  --panel: #23262f;
  --panel-2: #2a2e38;
  --line: #353a46;
  --text: #e7e9ee;
  --muted: #98a0b0;
  --accent: #4c8dff;
  --accent-2: #34c17b;
  --danger: #e5544b;
  --sel: #4c8dff;
  --radius: 8px;
  --app-min-width: 1280px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 13px;
  user-select: none;
}

/* Desktop contract: 1280 CSS px is the supported minimum. Narrower windows
   keep the complete desktop layout and scroll at the document boundary instead
   of silently clipping controls. Feature surfaces own their vertical overflow. */
html {
  min-width: var(--app-min-width);
  overflow-x: auto;
  overflow-y: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-width: var(--app-min-width);
  overflow: hidden;
}

/* ---------- Toolbar ---------- */
/* Осмысленные группы-«пилюли» в порядке работы: добавить → разложить → лист → проект → экспорт → вид.
   .tb-row = display:contents: группы текут одним потоком и переносятся без «сирот» на любой ширине. */
#toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.tb-row { display: contents; }
.tb-group {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 7px;
  background: rgba(255, 255, 255, .028);
  border: 1px solid rgba(255, 255, 255, .055);
  border-radius: 10px;
}
/* в тулбаре элементы компактнее, чем в панелях */
#toolbar .btn { padding: 6px 10px; }
#toolbar .btn.icon { padding: 5px 8px; }
#toolbar .select, #toolbar .num { padding: 5px 7px; }
#toolbar .num { width: 52px; }
#toolbar input[type="color"] { width: 30px; height: 28px; }
.tb-group.zoom { gap: 4px; }
.tb-menu { position: relative; flex: none; }
.tb-menu-trigger[aria-expanded="true"] { border-color: var(--accent); background: #333846; }
.tb-menu-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 230px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.tb-menu-pop.align-end { right: 0; left: auto; }
.tb-menu-item {
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.tb-menu-item:hover, .tb-menu-item:focus-visible { background: #333846; }
.tb-cap {
  font-size: 10px; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase;
  color: #78808f;
  margin: 0 4px 0 2px;
}
.tb-sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.tb-sep.small { height: 18px; }
.tb-spacer { flex: 1; }
.tb-label { color: var(--muted); font-size: 12px; }
.tb-check { cursor: pointer; white-space: nowrap; }
.tb-check input { vertical-align: -2px; margin-right: 4px; cursor: pointer; }
.proj-name {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  width: 150px;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #333846; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3f7ff0; }
.btn.accent { background: var(--accent-2); border-color: var(--accent-2); color: #06281a; font-weight: 600; }
.btn.accent:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 6px 8px; font-size: 12px; flex: 1; }
.btn.icon { padding: 6px 9px; font-size: 15px; line-height: 1; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- Unified confirm dialog ---------- */
.dialog-host {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 10, 14, .74);
}
.csm-dialog {
  width: min(460px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .58);
}
.csm-dialog-danger { border-color: var(--danger); box-shadow: 0 24px 64px rgba(82, 12, 12, .45); }
.csm-dialog-normal { border-color: var(--accent); }
.csm-dialog-header { display: flex; align-items: flex-start; gap: 16px; }
.csm-dialog-title { flex: 1; margin: 0; font-size: 17px; line-height: 1.35; }
.csm-dialog-danger .csm-dialog-title { color: #ffb5b0; }
.csm-dialog-close {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
}
.csm-dialog-close:hover { background: #333846; }
.csm-dialog-message {
  margin: 14px 0 20px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-line;
  user-select: text;
}
.csm-dialog-message:empty { display: none; }
.csm-dialog-form { display: grid; gap: 14px; }
.csm-dialog-form .csm-dialog-message { margin-bottom: 6px; }
.csm-dialog-body { display: grid; gap: 7px; }
.csm-dialog-label { color: var(--text); font-size: 12px; font-weight: 600; }
.csm-dialog-control {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  user-select: text;
}
textarea.csm-dialog-control { min-height: 110px; resize: vertical; }
.csm-dialog-error { min-height: 18px; color: var(--danger); font-size: 12px; line-height: 1.4; }
.csm-dialog-choices { min-width: 0; margin: 0; padding: 0; border: 0; display: grid; gap: 7px; }
.csm-dialog-choice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
.csm-dialog-choice-input { margin-top: 3px; }
.csm-dialog-choice-label { display: grid; gap: 3px; cursor: pointer; }
.csm-dialog-choice-name { color: var(--text); overflow-wrap: anywhere; }
.csm-dialog-choice-description { color: var(--muted); font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
.csm-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.csm-dialog-actions .btn { min-width: 110px; }

/* ---------- Web identity and account management ---------- */
.login-box.identity-login-box {
  width: min(640px, calc(100vw - 32px));
  max-height: min(820px, calc(100vh - 32px));
  overflow-y: auto;
  gap: 14px;
}
.identity-dialog-head,
.identity-dialog-toolbar,
.identity-banner-actions,
.identity-account-actions,
.identity-token-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.identity-dialog-head { align-items: flex-start; justify-content: space-between; }
.identity-dialog-head .login-title { margin: 0; }
.identity-close {
  flex: none;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.identity-close:hover,
.identity-close:focus-visible { color: var(--text); background: var(--panel-2); }
.identity-auth-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.identity-auth-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}
.identity-auth-tab.active,
.identity-auth-tab[aria-selected="true"] { border-color: var(--accent); color: var(--text); background: rgba(76, 141, 255, .12); }
.identity-auth-form { display: grid; gap: 7px; }
.identity-auth-form label,
.identity-field-label { color: var(--text); font-size: 12px; font-weight: 600; }
.identity-form-note,
.identity-field-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.identity-form-note.warning { color: #f4c56d; }
.identity-token-input,
.identity-token-code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.identity-auth-form input,
.identity-field input,
.identity-token-code { user-select: text; }
.identity-legacy-banner {
  position: relative;
  z-index: 20;
  flex: none;
  width: auto;
  margin: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 12px;
  border: 1px solid #9c6b22;
  border-radius: 10px;
  background: #392b18;
  color: #ffe2a6;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .35);
  font-size: 12px;
}
.identity-legacy-banner.hidden { display: none; }
.identity-banner-actions { flex: none; flex-wrap: wrap; justify-content: flex-end; }
.identity-modal {
  position: fixed;
  inset: 0;
  z-index: 100002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 6, 10, .76);
}
.identity-modal-panel {
  width: min(760px, calc(100vw - 32px));
  max-height: min(860px, calc(100vh - 32px));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 24px 72px rgba(0, 0, 0, .55);
}
.identity-modal-title { flex: 1; margin: 0; font-size: 18px; }
.identity-modal-content { display: grid; gap: 14px; }
.identity-section {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .018);
}
.identity-section-title { margin: 0; font-size: 14px; }
.identity-invite-grid { display: grid; grid-template-columns: 1fr 1.35fr minmax(120px, .7fr) auto; gap: 8px; align-items: end; }
.identity-field { display: grid; gap: 5px; min-width: 0; }
.identity-field input,
.identity-field select {
  width: 100%;
  box-sizing: border-box;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.identity-account-list { display: grid; gap: 8px; }
.identity-account-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
}
.identity-account-name { font-weight: 600; overflow-wrap: anywhere; }
.identity-account-meta { margin-top: 3px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.identity-account-actions { flex-wrap: wrap; justify-content: flex-end; }
.identity-account-actions label { display: grid; gap: 3px; color: var(--muted); font-size: 11px; }
.identity-account-actions select { min-width: 110px; }
.identity-token-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #8a6b25;
  border-radius: 9px;
  background: #302816;
}
.identity-token-code {
  display: block;
  padding: 8px;
  border-radius: 6px;
  background: #171717;
  color: #ffe8a8;
  overflow-wrap: anywhere;
  user-select: all;
}
.identity-status { min-height: 18px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.identity-status.error { color: var(--danger); }
.identity-status.success { color: #7bd99a; }
.legacy-recovery-card {
  display: grid;
  gap: 8px;
  margin: 7px 0 12px;
  padding: 10px;
  border: 1px solid #765f2d;
  border-radius: 9px;
  background: rgba(121, 90, 31, .12);
}
.legacy-recovery-title { margin: 0; color: var(--text); font-size: 13px; }
.legacy-recovery-status { min-height: 18px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.legacy-recovery-status.warning { color: #f4c56d; }
.legacy-recovery-status.error,
.legacy-recovery-error { color: var(--danger); }
.legacy-recovery-status.success { color: #7bd99a; }
.legacy-recovery-controls { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.legacy-recovery-form { width: 100%; display: grid; gap: 8px; }
.legacy-recovery-error { min-height: 18px; font-size: 12px; line-height: 1.45; }
.legacy-recovery-complete:disabled { opacity: 1; color: #7bd99a; border-color: #3f8157; }
.identity-modal-panel.task-center-dialog { width: min(920px, calc(100vw - 32px)); }
.task-center-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .018);
}
.task-center-intro { margin: 0; color: var(--text); font-size: 13px; line-height: 1.45; }
.task-center-contract-note { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.task-center-refresh { flex: none; }
.task-center-view { min-height: 120px; }
.task-center-message { margin: 0; padding: 20px 12px; color: var(--muted); text-align: center; }
.task-center-message.error { color: var(--danger); }
.task-center-section { display: grid; gap: 8px; }
.task-center-section + .task-center-section { margin-top: 18px; }
.task-center-section-title { margin: 0; color: var(--text); font-size: 14px; }
.task-center-section-note { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.task-center-list { display: grid; gap: 10px; }
.task-center-job {
  padding: 12px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 10px;
  background: var(--panel-2);
}
.task-center-job-queued { border-left-color: #d6a84c; }
.task-center-job-active { border-left-color: var(--accent); }
.task-center-job-succeeded { border-left-color: #55b879; }
.task-center-job-failed { border-left-color: var(--danger); }
.task-center-job-cancelled { border-left-color: #999; }
.task-center-receipt-reserved { border-left-color: #d6a84c; }
.task-center-receipt-active { border-left-color: #79b7ff; }
.task-center-receipt-manual {
  border-left-color: var(--danger);
  background: color-mix(in srgb, var(--panel-2) 88%, var(--danger));
}
.task-center-job-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.task-center-job-title { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.task-center-state {
  flex: none;
  padding: 3px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.task-center-state-queued { color: #e7bd69; }
.task-center-state-active { color: #79b7ff; }
.task-center-state-succeeded { color: #7bd99a; }
.task-center-state-failed { color: #ff9189; }
.task-center-state-cancelled,
.task-center-state-unknown { color: #bbb; }
.task-center-state-reserved { color: #e7bd69; }
.task-center-state-manual { color: #ff9189; }
.task-center-receipt-action,
.task-center-receipt-overflow {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--line));
  border-radius: 8px;
  color: #ffaaa3;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  font-size: 12px;
  line-height: 1.45;
}
.task-center-receipt-overflow { margin: 0; color: #f4c56d; border-color: #7f682f; }
.task-center-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 16px; margin-top: 9px; }
.task-center-meta-row { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px; font-size: 12px; line-height: 1.4; }
.task-center-meta-label { color: var(--muted); }
.task-center-meta-value { color: var(--text); overflow-wrap: anywhere; user-select: text; }
.task-center-result-link {
  display: inline-flex;
  width: max-content;
  margin-top: 10px;
  text-decoration: none;
}
.identity-modal :focus-visible,
.identity-login-box :focus-visible,
.identity-legacy-banner :focus-visible,
.legacy-recovery-card :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 900px) {
  .identity-legacy-banner { align-items: flex-start; flex-direction: column; }
  .identity-banner-actions { justify-content: flex-start; }
  .identity-invite-grid { grid-template-columns: 1fr; }
  .identity-account-row { grid-template-columns: 1fr; }
  .identity-account-actions { justify-content: flex-start; }
  .task-center-toolbar { flex-direction: column; }
  .task-center-meta { grid-template-columns: 1fr; }
}

.select, .num, input[type="color"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
.select.full, .num.full { width: 100%; }
.num { width: 62px; }
input[type="color"] { width: 34px; height: 32px; padding: 2px; cursor: pointer; }

:where(button, input, select, textarea, a[href], [tabindex]):focus-visible {
  outline: 2px solid #9bc5ff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(76, 141, 255, .24);
}

.zoom-label { min-width: 46px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Workspace ---------- */
#workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}
#workspace.hidden { display: none; }

/* Sidebar */
#sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
}
.sb-hint { color: var(--muted); font-size: 12px; margin-bottom: 10px; line-height: 1.4; }

.cat {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.cat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--panel-2);
  font-weight: 600;
}
.cat-head .count { color: var(--muted); font-weight: 400; font-size: 12px; }
.cat-drop {
  padding: 8px;
  min-height: 44px;
}
.cat-drop.drag-over { background: rgba(76,141,255,.12); outline: 2px dashed var(--accent); outline-offset: -6px; }
.dropzone-label {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 10px 4px;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.thumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px;
  border-radius: 6px;
  margin-bottom: 5px;
  cursor: pointer;
  background: var(--panel-2);
}
.thumb:hover { background: #333846; }
.thumb.selected { outline: 2px solid var(--sel); }
.thumb.hidden-item { opacity: .45; }
.thumb.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.thumb.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.thumb img {
  width: 40px; height: 40px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  flex: none;
}
.thumb .t-name {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thumb .t-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
}
.thumb .t-btn:hover { color: var(--text); background: rgba(255,255,255,.08); }

/* Viewport / board */
#viewport {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background:
    repeating-conic-gradient(#20242c 0% 25%, #191c22 0% 50%) 50% / 28px 28px;
  cursor: default;
}
#viewport.panning { cursor: grabbing; }
/* зажатый пробел — «рука»: курсор grab поверх всего, включая фото и маркеры */
#viewport.space-pan, #viewport.space-pan .item, #viewport.space-pan .handle { cursor: grab; }
#viewport.space-pan.panning, #viewport.space-pan.panning .item, #viewport.space-pan.panning .handle { cursor: grabbing; }

#board {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  /* will-change ставится ТОЛЬКО во время жеста (класс .gesture): в покое доска
     перерисовывается резко под текущий зум/DPI, а не растягивается кэш-текстурой (мыло как в старой версии) */
}
#board.gesture { will-change: transform; }

.item {
  position: absolute;
  outline: 1px solid rgba(0,0,0,.04);
}
.item .clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.item img {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  image-rendering: auto;
}
.item.selected { outline: none; }
.item .frame {
  position: absolute;
  inset: 0;
  border: calc(1.5px / var(--vs, 1)) solid var(--sel);
  pointer-events: none;
  display: none;
}
.item.selected .frame { display: block; }

.handle {
  position: absolute;
  width: calc(11px / var(--vs, 1));
  height: calc(11px / var(--vs, 1));
  background: #fff;
  border: calc(1.5px / var(--vs, 1)) solid var(--sel);
  border-radius: 2px;
  display: none;
  z-index: 5;
}
/* обычный режим: только углы (пропорциональный масштаб);
   края — только в режиме обрезки ✂, как в Figma */
.item.selected.solo .handle:not(.edge) { display: block; }

/* Текстовый блок на листе */
.item .tx {
  position: absolute;
  inset: 0;
  white-space: pre;
  line-height: 1.3;
  font-family: "Segoe UI", Arial, sans-serif;
  pointer-events: none;
  overflow: visible;
}
.item.text-item { outline: none; }

/* Режим обрезки: показываем все маркеры и подсвечиваем рамку оранжевым */
.item.crop-mode .handle { display: block; background: #ffb020; border-color: #ff8a00; }
.item.crop-mode .handle.edge { display: block; }
.item.crop-mode .frame { display: block; border-color: #ffb020; }

/* Режим «двигать кадр» (двойной клик): пунктирная рамка, курсор перемещения */
.item.pan-mode { cursor: move; }
.item.pan-mode .frame { display: block; border-style: dashed; }

/* «Магниты» моей раскладки: полупрозрачные ячейки видны только во время перетаскивания */
.slot-ghosts {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 55;
}
.slot-ghost {
  position: absolute;
  border: calc(2px / var(--vs, 1)) dashed rgba(124, 58, 237, 0.55);
  background: rgba(124, 58, 237, 0.07);
  border-radius: calc(6px / var(--vs, 1));
  transition: background 0.12s, border-color 0.12s;
}
.slot-ghost.hot {
  background: rgba(124, 58, 237, 0.22);
  border-color: rgba(124, 58, 237, 0.95);
  border-style: solid;
}
.slot-ghost .sg-name {
  position: absolute;
  top: calc(4px / var(--vs, 1));
  left: calc(6px / var(--vs, 1));
  font-size: calc(12px / var(--vs, 1));
  line-height: 1.4;
  color: rgba(93, 34, 196, 0.95);
  background: rgba(255, 255, 255, 0.78);
  padding: 0 calc(5px / var(--vs, 1));
  border-radius: calc(3px / var(--vs, 1));
  white-space: nowrap;
}

/* Вкладки и Примерочная */
#tabsBar { display: flex; align-items: flex-end; gap: 6px; min-width: 0; padding: 4px 10px 0; background: #1b1d21; border-bottom: 1px solid #2a2d33; }
#tabsBar .tab { background: transparent; color: #9aa0aa; border: 0; padding: 7px 16px; cursor: pointer; border-radius: 8px 8px 0 0; font-size: 13px; }
#tabsBar .tab.active { background: #24262c; color: #fff; }
#tabsBar #userBox {
  min-width: 0;
  max-width: 48%;
  margin: 0 0 4px auto;
  padding: 2px 4px 2px 8px;
}
#tabsBar #userLabel {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#tabsBar #btnLogout,
#tabsBar #btnAccountPassword,
#tabsBar #btnAccounts,
#tabsBar #btnTaskCenter { flex: none; padding: 4px 8px; font-size: 12px; }
#tryonView, #genView { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 16px; overflow: auto; background: #202227; }
#tryonView.hidden, #genView.hidden { display: none; }
#tryonView { gap: 0; padding: 0; overflow: hidden; }
.gen-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.gen-seed { width: 110px; }
.gen-refrow { margin-top: 4px; }
.gen-refdrop { flex: 1; min-width: 220px; min-height: 34px; display: flex; align-items: center; gap: 8px; padding: 6px 10px; color: var(--muted); font-size: 12px; border: 1px dashed var(--line); border-radius: 8px; cursor: pointer; }
.gen-refdrop.drag { border-color: var(--accent); background: rgba(76,141,255,.10); }
.gen-refdrop.has { color: var(--text); border-style: solid; }
.gen-refdrop img { width: 30px; height: 30px; object-fit: cover; border-radius: 4px; flex: none; }
textarea.tr-prompt { resize: vertical; font-family: inherit; }
.tr-left { flex: 1; max-width: 640px; }
.tryon-panel {
  width: 330px;
  min-width: 330px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #1b1d22;
  border-right: 1px solid #30343b;
  padding: 14px;
  box-sizing: border-box;
}
.tr-title { color: #d5d9e0; font-size: 14px; margin-bottom: 10px; }
.tr-slots { display: flex; gap: 12px; margin-bottom: 10px; }
.tryon-panel .tr-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tr-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.tr-slot { width: 150px; height: 200px; border: 2px dashed #4a4f59; border-radius: 10px; display: flex; align-items: center; justify-content: center; text-align: center; color: #8b919c; cursor: pointer; font-size: 13px; overflow: hidden; background: #26282e; }
.tryon-panel .tr-slot { width: auto; height: 128px; min-width: 0; border-radius: 8px; font-size: 12px; }
.tr-slot:hover { border-color: #7c3aed; color: #cbd0da; }
.tr-slot.filled { border-style: solid; border-color: #7c3aed; }
.tr-slot img { width: 100%; height: 100%; object-fit: cover; }
.tr-prompt { width: 100%; box-sizing: border-box; margin-bottom: 10px; padding: 8px 10px; border-radius: 8px; border: 1px solid #3a3e46; background: #26282e; color: #e8eaee; }
.tr-status { margin-top: 8px; color: #9aa0aa; font-size: 13px; min-height: 18px; }
.tr-result { margin-top: 10px; }
.tr-result img { max-width: 100%; max-height: 52vh; border-radius: 10px; border: 1px solid #3a3e46; }
.tr-history { width: 300px; flex: none; }
.tryon-history { width: auto; flex: 1; min-height: 0; margin-top: 16px; display: flex; flex-direction: column; }
.tryon-history #histList { overflow-y: auto; min-height: 0; padding-right: 2px; }
.tryon-stage {
  flex: 1;
  min-width: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 28px;
  box-sizing: border-box;
  background: #2b2f36;
}
.tryon-sheet {
  width: min(760px, 100%);
  min-height: calc(100vh - 150px);
  background: #f3f2ee;
  box-shadow: 0 14px 42px rgba(0,0,0,.42);
  border: 1px solid rgba(0,0,0,.08);
  padding: 28px;
  box-sizing: border-box;
  display: flex;
}
.tr-result-sheet {
  margin: 0;
  width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tr-result-sheet img {
  max-width: 100%;
  max-height: calc(100vh - 210px);
  object-fit: contain;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
}
.tryon-empty {
  color: #9a9a9a;
  font-size: 14px;
  text-align: center;
}
.hist-item { display: flex; align-items: center; gap: 8px; background: #26282e; border: 1px solid #33363e; border-radius: 8px; padding: 6px; margin-bottom: 8px; }
.hist-item[draggable="true"] { cursor: grab; }
.hist-item[draggable="true"]:active { cursor: grabbing; }
.hist-item img { width: 56px; height: 74px; object-fit: cover; border-radius: 6px; cursor: grab; flex: none; }
.hist-item .hi-meta { flex: 1; color: #aab0ba; font-size: 11.5px; line-height: 1.35; }
.hist-item .hi-acts { display: flex; flex-direction: column; gap: 4px; flex: none; }

/* слот примерочной — подсветка при перетаскивании с полки */
.tr-slot.drag-over { border-color: #7c3aed; background: #2e2740; }

/* Полка результатов — выезжающая панель справа, поверх обеих вкладок */
#resultTray {
  position: fixed; top: 0; right: 0; height: 100vh; width: 300px;
  background: #1c1e23; border-left: 1px solid #33363e; box-shadow: -6px 0 20px rgba(0,0,0,0.4);
  transform: translateX(100%); transition: transform 0.18s ease; z-index: 2000;
  display: flex; flex-direction: column; padding: 12px; box-sizing: border-box;
}
#resultTray.open { transform: translateX(0); }
#resultTray .tray-head { display: flex; align-items: center; justify-content: space-between; color: #e6e9ee; font-size: 14px; margin-bottom: 6px; }
#resultTray .tray-hint { color: #8b919c; font-size: 11.5px; margin-bottom: 10px; }
#trayList { overflow-y: auto; flex: 1; }

/* Курсор сотрудника в режиме наблюдения (координаты листа, компенсируем зум через --vs) */
.live-cursor {
  position: absolute;
  z-index: 60;
  pointer-events: none;
  transition: left 0.18s linear, top 0.18s linear;
}
.live-cursor .lc-dot {
  width: calc(12px / var(--vs, 1));
  height: calc(12px / var(--vs, 1));
  border-radius: 50%;
  background: #ff5722;
  border: calc(2px / var(--vs, 1)) solid #fff;
  box-shadow: 0 0 calc(6px / var(--vs, 1)) rgba(0, 0, 0, 0.45);
}
.live-cursor .lc-name {
  margin-top: calc(4px / var(--vs, 1));
  background: #ff5722;
  color: #fff;
  font-size: calc(12px / var(--vs, 1));
  padding: calc(2px / var(--vs, 1)) calc(6px / var(--vs, 1));
  border-radius: calc(4px / var(--vs, 1));
  white-space: nowrap;
  width: max-content;
}

/* Баннер режима наблюдения */
.live-banner {
  position: fixed;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  background: #7c3aed;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  display: flex;
  gap: 12px;
  align-items: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  font-size: 13px;
}
.live-banner button {
  background: #fff;
  color: #7c3aed;
  border: 0;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-weight: 600;
}

.handle.nw { left: calc(-6px / var(--vs, 1)); top: calc(-6px / var(--vs, 1)); cursor: nwse-resize; }
.handle.ne { right: calc(-6px / var(--vs, 1)); top: calc(-6px / var(--vs, 1)); cursor: nesw-resize; }
.handle.sw { left: calc(-6px / var(--vs, 1)); bottom: calc(-6px / var(--vs, 1)); cursor: nesw-resize; }
.handle.se { right: calc(-6px / var(--vs, 1)); bottom: calc(-6px / var(--vs, 1)); cursor: nwse-resize; }
.handle.n { top: calc(-6px / var(--vs, 1)); left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle.s { bottom: calc(-6px / var(--vs, 1)); left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle.w { left: calc(-6px / var(--vs, 1)); top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.handle.e { right: calc(-6px / var(--vs, 1)); top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.guide {
  position: absolute;
  background: #ff3b6b;
  display: none;
  z-index: 9999;
  pointer-events: none;
}
.guide.vertical { top: 0; width: calc(1px / var(--vs, 1)); height: 100%; }
.guide.horizontal { left: 0; height: calc(1px / var(--vs, 1)); width: 100%; }

.empty-hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: min(560px, calc(100% - 40px));
  padding: 22px 28px;
  border: 1px solid rgba(190, 201, 219, .28);
  border-radius: 14px;
  background: rgba(18, 21, 27, .92);
  box-shadow: 0 14px 36px rgba(0, 0, 0, .38);
  text-align: center;
  color: #cbd2de;
  pointer-events: none;
}
.empty-hint .eh-icon { font-size: 44px; margin-bottom: 10px; }
.empty-hint .eh-title { font-size: 17px; font-weight: 600; color: #fff; margin-bottom: 7px; }
.empty-hint .eh-text { font-size: 13.5px; line-height: 1.55; }
.empty-hint .eh-steps { margin: 10px 0 8px; padding-left: 24px; text-align: left; font-size: 12.5px; line-height: 1.55; }
.empty-hint .eh-terms { max-width: 480px; color: var(--muted); font-size: 11.5px; line-height: 1.4; text-align: left; }
.empty-hint.hidden { display: none; }

/* Inspector */
#inspector {
  width: 250px;
  min-width: 250px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px;
}
.insp-empty { color: var(--muted); font-size: 12px; line-height: 1.5; }
.insp-body.hidden, .insp-empty.hidden { display: none; }
.insp-name { font-weight: 600; margin-bottom: 2px; word-break: break-all; }
.insp-res { color: var(--muted); font-size: 12px; margin-bottom: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { color: var(--muted); font-size: 12px; }
.field-row { display: flex; gap: 8px; }
.field.small { flex: 1; }
.insp-tip { color: var(--muted); font-size: 11px; margin: -4px 0 12px; line-height: 1.4; display: none; }
.insp-tip.show { display: block; }
.insp-actions { display: flex; gap: 6px; margin-bottom: 8px; }

#photoProps.hidden, #textProps.hidden { display: none; }
.hidden, .hidden0 { display: none !important; }
.web-modal-sec {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin: 10px 0 2px;
  text-transform: none;
}
#ispZoom { width: 100%; cursor: pointer; }
.insp-hint { color: var(--muted); font-weight: 400; font-size: 11px; }
.ratio-row { display: flex; gap: 4px; flex-wrap: wrap; }
.ratio-row .btn { flex: 1; padding: 5px 4px; font-size: 12px; }
.txtarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  width: 100%;
  resize: vertical;
  font-family: inherit;
}
#txColor { width: 100%; height: 32px; }

/* Statusbar */
#statusbar {
  height: 26px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.build-tag {
  margin-left: auto;
  padding-left: 12px;
  color: var(--muted);
  font-size: 11px;
  opacity: .8;
  white-space: nowrap;
}

/* Общий drop-overlay при перетаскивании файлов в окно */
#viewport.drag-over::after {
  content: "Отпустите, чтобы добавить фото";
  position: absolute;
  inset: 16px;
  border: 3px dashed var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 18px;
  background: rgba(76,141,255,.08);
  z-index: 10000;
  pointer-events: none;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #3a3f4c; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* --- Панель-план «Макро» --- */
.macro-plan {
  position: fixed; inset: 0; z-index: 10001;
  background: rgba(10, 12, 16, .62);
  display: flex; align-items: center; justify-content: center;
}
.macro-plan.hidden { display: none; }
.macro-plan .mp-box {
  width: min(560px, 94vw); max-height: 90vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 18px 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.mp-title { color: #e6e9ee; font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.mp-sub { color: #8b919c; font-size: 12px; line-height: 1.4; margin-bottom: 12px; }
.mp-note {
  width: 100%; box-sizing: border-box; resize: vertical;
  background: var(--panel-2); color: #e6e9ee; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px;
}
.mp-count-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; color: #b9bfc9; font-size: 13px; }
.mp-cnt {
  min-width: 32px; height: 30px; padding: 0 8px;
  background: var(--panel-2); color: #cfd4dd; border: 1px solid var(--line);
  border-radius: 7px; cursor: pointer; font-size: 13px;
}
.mp-cnt:hover { border-color: var(--accent); }
.mp-cnt.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.mp-slot-hint { color: #8b919c; font-size: 11.5px; margin-left: 4px; flex-basis: 100%; }
.mp-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.mp-row { display: flex; align-items: center; gap: 8px; }
.mp-idx {
  flex: 0 0 22px; height: 22px; line-height: 22px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 50%;
  color: #8b919c; font-size: 12px;
}
.mp-desc {
  flex: 1 1 auto; min-width: 0;
  background: var(--panel-2); color: #e6e9ee; border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 9px; font-size: 13px;
}
.mp-zoom {
  flex: 0 0 130px;
  background: var(--panel-2); color: #e6e9ee; border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 6px; font-size: 12.5px;
}
.mp-actions { display: flex; align-items: center; gap: 8px; }
.mp-spacer { flex: 1 1 auto; }

/* 2-й реф — щит-лист вещей */
.mp-items-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; margin-bottom: 12px; padding: 8px;
  background: rgba(255, 255, 255, .03); border: 1.5px dashed var(--line); border-radius: 8px;
  color: #8b919c; cursor: pointer; position: relative; overflow: hidden; text-align: center;
  transition: border-color .12s, background .12s;
}
.mp-items-drop:hover { border-color: var(--accent); background: rgba(76, 141, 255, .08); }
.mp-items-drop.drag { border-color: var(--accent); background: rgba(76, 141, 255, .14); }
.mp-items-drop.has-image { border-style: solid; min-height: 92px; padding: 0; }
.mp-items-drop img { width: 100%; height: 92px; object-fit: contain; background: #1a1d24; border-radius: 6px; }
.mp-items-cap { font-size: 13px; color: #cfd4dd; }
.mp-items-sub { font-size: 11px; color: #8b919c; }
.mp-items-x {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; line-height: 20px;
  border: none; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; font-size: 13px;
}
.mp-items-x:hover { background: rgba(0, 0, 0, .8); }

/* Живой предпросмотр промта */
.mp-preview-wrap { margin-bottom: 14px; }
.mp-preview-head { color: #8b919c; font-size: 11.5px; margin-bottom: 4px; }
.mp-preview {
  width: 100%; box-sizing: border-box; resize: vertical;
  background: #1a1d24; color: #b9bfc9; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 11.5px; line-height: 1.45; font-family: ui-monospace, Consolas, monospace;
  max-height: 160px;
}

/* --- «Перенос кожи головы» --- */
.skintx { position: fixed; inset: 0; z-index: 10001; background: rgba(10,12,16,.62); display: flex; align-items: center; justify-content: center; }
.skintx.hidden { display: none; }
.stx-box { width: min(900px, 96vw); max-height: 92vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.stx-head { display: flex; align-items: center; justify-content: space-between; color: #e6e9ee; font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.stx-sub { color: #8b919c; font-size: 12px; line-height: 1.4; margin-bottom: 12px; }
.stx-main { display: flex; gap: 14px; align-items: flex-start; }
.stx-canvas-wrap { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; background: #14161c; border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-height: 300px; }
.stx-canvas-wrap canvas { max-width: 100%; height: auto; border-radius: 6px; cursor: grab; }
.stx-canvas-wrap canvas:active { cursor: grabbing; }
.stx-side { flex: 0 0 250px; display: flex; flex-direction: column; gap: 8px; }
.stx-drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; padding: 6px; background: rgba(255,255,255,.03); border: 1.5px dashed var(--line); border-radius: 8px; color: #cfd4dd; font-size: 12px; cursor: pointer; position: relative; overflow: hidden; text-align: center; }
.stx-drop:hover { border-color: var(--accent); }
.stx-drop.drag { border-color: var(--accent); background: rgba(76,141,255,.14); }
.stx-drop.has-image { border-style: solid; padding: 0; min-height: 70px; }
.stx-drop img { width: 100%; height: 70px; object-fit: contain; background: #1a1d24; border-radius: 6px; }
.stx-sub2 { font-size: 10.5px; color: #8b919c; }
.stx-badge { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 6px; }
.stx-ctl { display: flex; flex-direction: column; gap: 2px; color: #b9bfc9; font-size: 11.5px; }
.stx-ctl input[type=range] { width: 100%; }
.stx-ctl2 { color: #cfd4dd; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.stx-actions { margin-top: 6px; }
.stx-box.stx-compact { width: min(440px, 94vw); }
.stx-compact .stx-drop { min-height: 64px; margin-bottom: 10px; }
.stx-compact .stx-drop.has-image { min-height: 100px; }
.stx-compact .stx-drop img { height: 100px; }
.stx-sheetinfo { color: #cfd4dd; font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; }
/* плавающий бар сверки переноса кожи (холст остаётся виден для сравнения) */
.stx-review { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 10002;
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 48px rgba(0,0,0,.55); }
.stx-review.hidden { display: none; }
.stx-review-lbl { color: #e6e9ee; font-size: 13px; font-weight: 600; }

/* ---------- Автоматизация (вкладка ⚙): миссии и конвейер этапов ---------- */
#autoView { flex: 1; display: flex; min-height: 0; }
#autoView.hidden { display: none; }
.auto-side { width: 270px; min-width: 270px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.auto-side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.auto-list { overflow-y: auto; padding: 8px; flex: 1; }
.auto-item { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; cursor: pointer; background: var(--panel-2); }
.auto-item:hover { background: #333846; }
.auto-item.active { border-color: var(--accent); }
.ai-name { font-weight: 600; margin-bottom: 2px; }
.mission-version { display: inline-flex; align-items: center; padding: 1px 5px; margin-right: 4px; border: 1px solid #596273; border-radius: 999px; color: #c9d1df; font-size: 9.5px; font-weight: 700; letter-spacing: .04em; line-height: 1.35; vertical-align: 1px; }
.mission-version-v3 { border-color: #477fba; background: rgba(76, 141, 255, .14); color: #bcd9ff; }
.mission-version-legacy { border-color: #77684a; background: rgba(255, 176, 32, .1); color: #f0cf91; }
.ai-meta { color: var(--muted); font-size: 11.5px; }
.auto-none { color: var(--muted); font-size: 12px; padding: 8px; line-height: 1.5; }
.auto-main { flex: 1; overflow-y: auto; padding: 14px 18px; min-width: 0; }
.auto-readonly-banner { max-width: 980px; margin: 0 0 12px; padding: 9px 12px; border: 1px solid #55708f; border-radius: 7px; background: #1d2a38; color: #cfe5ff; font-size: 13px; }
body.csm-auto-readonly #autoStages :is(button, input, select, textarea):disabled { opacity: .52; cursor: not-allowed; }
body.csm-auto-readonly #autoList .ai-del { display: none; }
body.csm-readonly #workspace .item,
body.csm-readonly #library .thumb { cursor: not-allowed !important; }
.auto-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--muted); text-align: center; gap: 8px; }
.auto-empty.hidden, #autoBoard.hidden { display: none; }
.auto-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.auto-title { font-size: 17px; font-weight: 700; }
.auto-meta { color: var(--muted); font-size: 12px; }
.auto-stages { display: flex; flex-direction: column; gap: 10px; max-width: 980px; }
.auto-stage { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.auto-stage.st-run { border-left-color: var(--accent); }
.auto-stage.st-ready { border-left-color: #ffb020; }
.auto-stage.st-done { border-left-color: var(--accent-2); }
.auto-stage.st-error { border-left-color: var(--danger); }
.as-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.as-name { font-weight: 600; }
.as-chip { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.as-note { color: #ffb020; font-size: 12px; margin-top: 4px; }
.st-error .as-note { color: var(--danger); }
.as-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.as-thumb { position: relative; display: block; width: 76px; height: 100px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #14161c; }
.as-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.as-thumb.locked { outline: 2px solid var(--accent-2); }
.as-lock { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(6,40,26,.85); color: #6ee7a8; font-size: 10.5px; text-align: center; padding: 1px 0; }
.as-var { display: flex; flex-direction: column; gap: 4px; }
.as-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.as-actions .btn.sm { flex: none; }
.auto-log-head { margin: 16px 0 6px; font-weight: 600; color: var(--muted); }
.auto-log { background: #14161c; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-height: 180px; overflow-y: auto; font-size: 11.5px; color: #b7bfcc; max-width: 980px; }
.al-line { padding: 1px 0; }
/* убрать файл из этапа + документ-чип (сценарий) + подсказка этапа */
.as-x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px; line-height: 1; cursor: pointer; display: none; padding: 0; }
.as-thumb:hover .as-x { display: block; }
.as-x:hover { background: var(--danger); }
.as-thumb.as-doc { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-decoration: none; }
.as-doc-ic { font-size: 26px; }
.as-doc-ext { font-size: 10.5px; color: var(--muted); letter-spacing: .06em; }
.as-hint { color: var(--muted); font-size: 11.5px; margin-top: 6px; line-height: 1.45; }
/* конвейер-«дамба»: паспорт, подписи зон, план сценария */
.auto-side-btns { display: flex; gap: 6px; }
.auto-item.sc { border-left: 3px solid var(--accent); }
.auto-ctl { margin: 0 0 2px; }
.as-cap { color: var(--muted); font-size: 11px; margin-top: 8px; letter-spacing: .04em; }
.as-cap-res { color: #6ee7a8; }
.as-results .as-thumb { outline: 1px solid rgba(52,193,123,.5); }
.as-pass { margin-top: 6px; background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5; }
.ap-row b { color: var(--muted); font-weight: 600; }
.ap-en span { color: var(--muted); font-size: 11.5px; }
.sc-looks { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.sc-look { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; line-height: 1.45; cursor: pointer; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.sc-look input { margin-top: 2px; }
/* удаление из списка конвейера + общий чекбокс плана */
.auto-item { position: relative; }
.ai-del { position: absolute; top: 6px; right: 6px; display: none; border: none; background: transparent; cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 5px; }
.auto-item:hover .ai-del { display: block; }
.ai-del:hover { background: rgba(229,84,75,.25); }
.sc-master { background: rgba(76,141,255,.08); border-color: rgba(76,141,255,.4); }
.sc-char { display: flex; align-items: center; gap: 8px; cursor: pointer; }
/* лайтбокс превью в полном качестве + кнопка переделки на превью */
#autoLightbox { position: fixed; inset: 0; z-index: 10005; background: rgba(10,11,14,.92); display: none; align-items: center; justify-content: center; flex-direction: column; gap: 10px; cursor: zoom-out; }
#autoLightbox.show { display: flex; }
#autoLightbox img { max-width: 96vw; max-height: 90vh; object-fit: contain; border-radius: 6px; box-shadow: 0 24px 80px rgba(0,0,0,.7); }
#autoLightbox .lb-bar { display: flex; gap: 16px; align-items: center; color: var(--muted); font-size: 12.5px; }
#autoLightbox .lb-open { color: var(--accent); text-decoration: none; }
.as-redo { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px; line-height: 1; cursor: pointer; display: none; padding: 0; }
.as-thumb:hover .as-redo { display: block; }
.as-redo:hover { background: var(--accent); }
/* живые кнопки, заглушка генерации, версии, группировка персонажей */
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ''; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: asspin .7s linear infinite; }
@keyframes asspin { to { transform: rotate(360deg); } }
.auto-stage.st-run { position: relative; }
.auto-stage.st-run::before { content: ''; position: absolute; left: -4px; top: 0; bottom: 0; width: 4px;
  border-radius: 10px 0 0 10px; background: linear-gradient(180deg, var(--accent), #7fb2ff, var(--accent));
  background-size: 100% 220%; animation: asflow 1.6s linear infinite; }
@keyframes asflow { to { background-position: 0 220%; } }
.as-ghost { width: 76px; height: 100px; border-radius: 8px; border: 1px dashed rgba(76,141,255,.6);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: #9db9e8; font-size: 10.5px; background: linear-gradient(110deg, rgba(76,141,255,.08) 30%, rgba(127,178,255,.22) 50%, rgba(76,141,255,.08) 70%);
  background-size: 220% 100%; animation: asshimmer 1.4s linear infinite; }
.as-ghost em { font-style: normal; }
@keyframes asshimmer { to { background-position: -220% 0; } }
.as-versions { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.as-versions .as-cap { margin: 0; }
.as-ver-cur { font-size: 11px; color: #6ee7a8; border: 1px solid rgba(52,193,123,.45); border-radius: 6px; padding: 3px 8px; cursor: default; background: rgba(52,193,123,.10); }
.ai-group { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; margin: 10px 2px 6px; font-weight: 600; }
.auto-item.grouped { margin-left: 8px; }
/* вкладки луков внутри карточки персонажа + пометки образов */
.auto-looks-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 4px; }
.auto-item.person { border-left: 3px solid var(--accent-2); }
.as-var-label { font-size: 10.5px; color: var(--muted); text-align: center; max-width: 90px; line-height: 1.3; }

/* ===== Автоматизация v3: колоды, родители, прогоны ===== */
.automation-v3-overview { position: relative; border: 1px solid #4b6482; border-radius: 12px; padding: 10px 12px; background: #1b2633; display: flex; flex-direction: column; gap: 8px; }
.automation-v3-overview-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.automation-v3-metrics, .automation-v3-statuses, .automation-v3-decisions, .automation-v3-route-group { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 8px; }
.automation-v3-metric { border: 1px solid #48617d; border-radius: 999px; padding: 2px 7px; color: #d8e9ff; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.automation-v3-statuses { align-items: flex-start; }
.automation-v3-status-group { display: inline-flex; flex-wrap: wrap; gap: 4px 7px; color: var(--muted); font-size: 11px; }
.automation-v3-status-group b, .automation-v3-decisions > b { color: var(--text); }
.automation-v3-decisions { padding-top: 2px; }
.automation-v3-navigation { border-top: 1px solid #3c4c60; padding-top: 6px; }
.automation-v3-navigation summary { color: #bdd8f5; cursor: pointer; font-size: 12px; font-weight: 650; }
.automation-v3-route-group { margin-top: 7px; }
.automation-v3-route-group > span { min-width: 74px; color: var(--muted); font-size: 11px; }
.automation-v3-route-button.active { border-color: var(--accent); background: rgba(76,141,255,.2); color: #e6f1ff; }
.automation-v3-route-focus { outline: 2px solid rgba(76,141,255,.75); outline-offset: 3px; }
.v3-section { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 10px 0; background: var(--panel); }
.v3-sec-head { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.v3-sec-head.sm { font-size: 13px; margin: 12px 0 4px; }
.v3-decks { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 4px; align-items: flex-start; }
.v3-deck { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--panel-2); width: 252px; display: flex; flex-direction: column; gap: 7px; }
.v3-deck.st-run { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(90,140,255,.18); }
.v3-deck-title { font-size: 12.5px; font-weight: 650; line-height: 1.35; }
.v3-deck-desc { color: var(--muted); font-size: 11px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.v3-deck .as-thumb.v3-card { width: 100%; height: 300px; }
.v3-deck .as-ghost.v3-card { width: 100%; height: 300px; }
.v3-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.v3-run { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 6px; }
.as-thumb .as-folder { position: absolute; right: 26px; top: 2px; border: 0; background: rgba(20,22,28,.8); color: var(--text); border-radius: 6px; cursor: pointer; font-size: 12px; padding: 1px 4px; display: none; }
.as-thumb:hover .as-folder { display: block; }
.v3-card .as-redo2 { position: absolute; left: 2px; top: 2px; border: 0; background: rgba(20,22,28,.8); color: var(--text); border-radius: 6px; cursor: pointer; font-size: 13px; padding: 1px 6px; display: none; }
.v3-card:hover .as-redo2 { display: block; }
#autoLightbox .lb-reveal { margin-left: 10px; }
.v3-section .auto-looks-tabs button { flex: 0 0 auto; width: auto; }
.as-thumb.as-dimmed img { opacity: .3; filter: grayscale(.9); }
.as-thumb.as-dimmed { border-style: dashed; }
.as-thumb.as-active { outline: 2px solid var(--accent-2); }
.as-active-tag { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(6,40,26,.85); color: #6ee7a8; font-size: 10px; text-align: center; padding: 1px 0; }
.as-pick { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); border: 0; border-radius: 8px; background: var(--accent-2, #34c17b); color: #08130c; font-size: 11px; font-weight: 700; padding: 4px 8px; cursor: pointer; }
.v3-deck-nav { display: flex; align-items: center; justify-content: center; gap: 8px; }
.v3-nav-btn { min-width: 34px; font-weight: 700; }
.v3-deck-num { font-size: 12px; color: var(--muted); min-width: 44px; text-align: center; }
.v3-stash { border-style: dashed; opacity: .92; }
.v3-pairs { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; }
.v3-pair { display: flex; align-items: center; gap: 6px; }
.v3-pair-col { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.v3-pair-col .as-cap { margin: 0; }
.v3-pair-arrow { color: var(--muted); font-size: 16px; }
.as-head-right { display: flex; align-items: center; gap: 8px; }
.as-timer { font-size: 11.5px; color: var(--accent, #7aa7e0); font-variant-numeric: tabular-nums; }
.as-timer.done { color: var(--muted); }
.v3-waitbar { border: 1px solid var(--line); border-left: 4px solid #ffb020; border-radius: 10px; padding: 8px 12px; margin: 8px 0; background: var(--panel); font-size: 12.5px; }
.v3-waitbar.idle { border-left-color: var(--accent-2, #34c17b); }
.v3-waitlist { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; color: var(--text); }
#apOverlay { position: fixed; inset: 0; background: rgba(10,12,16,.72); z-index: 340; display: flex; align-items: center; justify-content: center; }
.ap-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; width: 520px; max-height: 86vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.ap-title { font-weight: 700; font-size: 15px; }
.ap-sec { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.ap-sec-head { font-size: 12.5px; font-weight: 650; margin-bottom: 2px; }
.ap-sec.ap-paid { border-color: #7a4040; background: rgba(160,60,60,.07); }
.ap-toggle { display: flex; align-items: center; gap: 10px; font-size: 12.5px; cursor: pointer; }
.ap-toggle input { width: 34px; height: 18px; appearance: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; position: relative; cursor: pointer; transition: background .15s; flex: 0 0 auto; }
.ap-toggle input::after { content: ''; position: absolute; top: 1px; left: 1px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: left .15s, background .15s; }
.ap-toggle input:checked { background: var(--accent-2, #34c17b); border-color: var(--accent-2, #34c17b); }
.ap-paid .ap-toggle input:checked { background: #d9534f; border-color: #d9534f; }
.ap-toggle input:checked::after { left: 17px; background: #fff; }
.ap-own { margin-top: 6px; }
.ap-disabled { opacity: .45; pointer-events: none; }
.ap-actions { justify-content: flex-end; }
.v3-waitbar.paused { border-left-color: #d9534f; background: rgba(180,70,60,.10); }
.v3-waitbar.paused .btn { margin-top: 6px; }

/* очередь GPT: бейдж в сайдбаре конвейера */
.gpt-queue { margin: 6px 10px 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.gpt-queue b { color: var(--text); font-variant-numeric: tabular-nums; }
.gpt-queue.busy { border-left: 4px solid var(--accent, #7aa7e0); }
.gpt-queue.jam { border-left: 4px solid #ffb020; }

/* редактор профиля финального щит-листа */
#sheetOverlay { position: fixed; inset: 0; background: rgba(10,12,16,.72); z-index: 340; display: flex; align-items: center; justify-content: center; }
#sheetOverlay .ap-panel { width: 640px; }
.sheet-row { display: flex; gap: 8px; align-items: center; }
.sheet-row input[type=text] { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 6px 9px; font-size: 12.5px; }
.sheet-row select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 6px 6px; font-size: 12px; flex: 0 0 auto; }
.sheet-row .btn { flex: 0 0 auto; }
.sheet-num { flex: 0 0 auto; width: 18px; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
/* карточка одежды (2-й реф) в карточке настроек финала */
.sheet-refbox { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--panel-2); }
.sheet-refbox img { width: 88px; height: 88px; object-fit: contain; background: #fff; border-radius: 8px; flex: 0 0 auto; }
.sheet-refcap { font-size: 12px; color: var(--muted); line-height: 1.4; }
/* read-only предпросмотр промта */
.sheet-prevwrap { display: flex; flex-direction: column; gap: 4px; }
.sheet-prev { width: 100%; box-sizing: border-box; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; color: var(--muted); padding: 8px 10px; font-size: 11.5px; line-height: 1.45; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; resize: vertical; }
/* плавающий бар возврата щита в миссию */
#sheetReturnBar { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 350; display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--accent, #7aa7e0); border-radius: 12px; padding: 10px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
#sheetReturnBar .srb-copy { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
#sheetReturnBar .srb-text { font-size: 12.5px; color: var(--text); max-width: 460px; }
#sheetReturnBar .srb-error { max-width: 460px; color: #ffb0aa; font-size: 11.5px; line-height: 1.35; }
#sheetReturnBar .srb-error:empty { display: none; }

/* Компактный рабочий режим для типичных ноутбучных/HD-окон без потери действий. */
@media (max-width: 1400px) {
  #toolbar {
    gap: 4px 6px;
    padding: 6px 8px;
  }
  #toolbar .tb-group {
    min-width: 0;
    max-width: calc(100vw - 16px);
    gap: 4px;
    padding: 2px 5px;
  }
  #toolbar .tb-cap { margin-inline: 1px 3px; font-size: 9px; }
  #toolbar .btn { padding: 5px 8px; font-size: 12px; }
  #toolbar .btn.icon { padding: 5px 7px; }
  #toolbar .select, #toolbar .num { padding: 4px 6px; font-size: 12px; }
  #toolbar .proj-name { width: 130px; padding: 5px 7px; font-size: 12px; }
  #toolbar #layoutPreset { max-width: 160px; }
  #toolbar #boardPreset { max-width: 170px; }
  #toolbar #exportSize { max-width: 160px; }

  #tabsBar { padding-inline: 8px; }
  #tabsBar .tab { padding-inline: 12px; }
  #tabsBar #userBox { max-width: 38%; }

  #sidebar { width: 210px; min-width: 210px; padding: 8px; }
  #inspector { width: 220px; min-width: 220px; padding: 10px; }
  #resultTray { width: 280px; }
  .tryon-panel { width: 290px; min-width: 290px; padding: 12px; }
  #genView > .tr-history { width: 260px; }
  .auto-side { width: 240px; min-width: 240px; }
  .auto-side-head { align-items: flex-start; gap: 6px; flex-wrap: wrap; padding: 8px 10px; }
  .auto-side-btns { flex-wrap: wrap; }
  .auto-main { padding: 12px 14px; }
}
