/* =========================================================
   TEKSTO — редактор виджетов (HTML bubbles)
   Использует токены из styles.css. Цвет — только для ошибок.
   ========================================================= */

:root {
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.12);
}

.widget-workspace {
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
}

.widget-page .editor-pane {
  position: relative;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
}

.widget-page .pane-head .pane-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- конструктор ---------- */

.wg-scroll {
  min-height: 0;
  overflow: auto;
}

.wg-builder {
  display: grid;
  gap: 10px;
  padding: 2px 16px 48px;
}

.tpl-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--fg);
}

.tpl-icon .i {
  width: 20px;
  height: 20px;
}

.tpl-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.tpl-text b {
  font-size: 14px;
  font-weight: 600;
}

.tpl-text small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wg-note {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--fg-2);
  font-size: 12.5px;
  line-height: 1.5;
}

.wg-note .i {
  width: 17px;
  height: 17px;
  margin-top: 1px;
  color: var(--muted);
}

.wg-note b {
  color: var(--fg);
  font-weight: 500;
}

.row-actions {
  display: flex;
  gap: 6px;
}

/* шапка шаблона */

.tpl-hero {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
}

.tpl-hero .tpl-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--fg);
  color: var(--bg);
}

.tpl-hero .tpl-icon .i {
  width: 22px;
  height: 22px;
}

.tpl-hero .tpl-text b {
  font-size: 15px;
}

.tpl-hero .tpl-text small {
  white-space: normal;
  line-height: 1.4;
}

.tpl-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tpl-tags span {
  padding: 2px 8px;
  border-radius: 99px;
  box-shadow: inset 0 0 0 1px var(--line-strong);
  color: var(--fg-2);
  font-size: 11px;
}

.tpl-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-column: 1 / -1;
  gap: 6px;
}

.tpl-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--fg-2);
  font-size: 12.5px;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}

.tpl-actions button:hover {
  border-color: var(--line-strong);
  background: var(--surface-3);
  color: var(--fg);
}

.tpl-actions .i {
  width: 15px;
  height: 15px;
}

/* навигация по разделам */

.sec-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  margin: 0 -16px;
  padding: 8px 16px;
  overflow-x: auto;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.sec-nav::-webkit-scrollbar {
  display: none;
}

.sec-nav button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  height: 30px;
  padding: 0 11px 0 9px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background var(--ease), color var(--ease);
}

.sec-nav button .i {
  width: 15px;
  height: 15px;
}

.sec-nav button:hover {
  color: var(--fg);
}

.sec-nav button.active {
  background: var(--surface-3);
  color: var(--fg);
}

/* разделы */

.wg-group {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  scroll-margin-top: 56px;
}

.wg-group > summary {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.wg-group > summary::-webkit-details-marker {
  display: none;
}

.grp-ico {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--fg);
}

.grp-ico .i {
  width: 17px;
  height: 17px;
}

.wg-group[open] .grp-ico {
  background: var(--fg);
  color: var(--bg);
}

.grp-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.grp-text b {
  font-size: 13.5px;
  font-weight: 600;
}

.grp-sum {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wg-group > summary > .i {
  width: 16px;
  height: 16px;
  color: var(--muted);
  transform: rotate(-90deg);
  transition: transform var(--ease);
}

.wg-group[open] > summary > .i {
  transform: none;
}

.wg-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 10px;
  margin: 0 12px;
  padding: 14px 0 16px;
  border-top: 1px solid var(--line);
}

.wf {
  display: grid;
  grid-column: 1 / -1;
  align-content: start;
  gap: 6px;
  min-width: 0;
}

.wf-half {
  grid-column: auto;
}

.wf-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--fg-2);
  font-size: 12.5px;
}

.wf-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wf-ico {
  width: 14px;
  height: 14px;
  color: var(--faint);
}

/* список переключателей */

.sw-list {
  display: grid;
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
}

.sw-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.sw-row:first-child {
  border-top: 0;
}

.sw-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sw-text b {
  color: var(--fg);
  font-size: 13px;
  font-weight: 400;
}

.sw-text small {
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.4;
}

.sw-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sw {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 99px;
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: background var(--ease);
}

.sw::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--ease), background var(--ease);
}

.sw-row input:checked + .sw {
  background: var(--fg);
  box-shadow: none;
}

.sw-row input:checked + .sw::after {
  transform: translateX(14px);
  background: var(--bg);
}

.sw-row input:focus-visible + .sw {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

/* палитры */

.palettes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
}

.pal {
  position: relative;
  display: grid;
  place-items: center;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.3);
  cursor: pointer;
  transition: transform var(--ease), box-shadow var(--ease);
}

.pal:hover {
  transform: translateY(-1px);
}

.pal.is-active {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg);
}

.pal span {
  font-size: 13px;
  font-weight: 700;
}

.pal i {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.25);
}

.wf-hint {
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.45;
}

.wf-count {
  justify-self: end;
  color: var(--faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.wf-count.is-over {
  color: var(--danger);
}

.wg-builder input[type="text"],
.wg-builder input[type="number"],
.wg-builder input[type="datetime-local"],
.wg-builder textarea,
.wg-builder select,
.sim-menu select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--fg);
  font-size: 13.5px;
  outline: none;
  transition: border-color var(--ease);
}

.wg-builder textarea {
  height: auto;
  min-height: 64px;
  padding: 8px 11px;
  line-height: 1.5;
  resize: vertical;
}

.wg-builder select,
.sim-menu select,
.compact-select {
  appearance: none;
  padding-right: 30px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 14px;
  cursor: pointer;
}

.wg-builder input:focus,
.wg-builder textarea:focus,
.wg-builder select:focus,
.sim-menu select:focus {
  border-color: var(--faint);
}

.wg-builder input::placeholder,
.wg-builder textarea::placeholder {
  color: var(--faint);
}

.wg-builder input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  opacity: 0.55;
  cursor: pointer;
}

.seg-field {
  display: flex;
  width: 100%;
}

.seg-field button {
  flex: 1 1 0;
  justify-content: center;
  min-width: 0;
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.num-field {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 4px;
}

.num-field input {
  text-align: center;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}

.num-field input::-webkit-outer-spin-button,
.num-field input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.num-field button {
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--fg-2);
  font-size: 16px;
  transition: background var(--ease), color var(--ease);
}

.num-field button:hover {
  background: var(--surface-3);
  color: var(--fg);
}

.range-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
}

.range-field output {
  color: var(--fg-2);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.range-field input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.range-field input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: var(--surface-3);
}

.range-field input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  -webkit-appearance: none;
}

.range-field input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: var(--surface-3);
}

.range-field input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
}

.color-field {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 6px;
}

.swatch {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: var(--r);
  background: var(--swatch, #000);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  cursor: pointer;
}

.swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.color-field input[type="text"] {
  font-family: var(--mono);
  font-size: 13px;
  text-transform: lowercase;
}

.list-field {
  display: grid;
  gap: 4px;
}

.lf-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 28px 28px;
  align-items: center;
  gap: 4px;
}

.lf-num {
  color: var(--faint);
  font-size: 11.5px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.lf-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--faint);
  font-size: 16px;
  transition: background var(--ease), color var(--ease);
}

.lf-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--fg);
}

.lf-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.bf-row {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr) 28px;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r);
}

.bf-row .bf-label {
  grid-column: 1 / 3;
  font-weight: 500;
}

.bf-row select {
  grid-row: 2;
}

.bf-row input:not(.bf-label) {
  grid-row: 2;
  grid-column: 2 / 4;
}

/* ---------- галерея шаблонов ---------- */

.wg-gallery {
  position: fixed;
  inset: var(--gallery-top, 56px) 0 0 0;
  z-index: 30;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--bg);
  animation: pop-in 140ms ease;
}

.wg-gallery[hidden] {
  display: none;
}

.gallery-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 340px) auto;
  align-items: center;
  gap: 16px;
  padding: 18px 20px 10px;
}

.gallery-title h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
}

.gallery-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.gallery-search {
  position: relative;
  display: flex;
  align-items: center;
}

.gallery-search .i {
  position: absolute;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.gallery-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--fg);
  font-size: 14px;
  outline: none;
}

.gallery-search input:focus {
  border-color: var(--faint);
}

.gallery-cats {
  display: flex;
  gap: 6px;
  padding: 0 20px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.gallery-cats::-webkit-scrollbar {
  display: none;
}

.gallery-cats button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  color: var(--fg-2);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.gallery-cats button span {
  color: var(--faint);
  font-size: 11px;
}

.gallery-cats button:hover {
  border-color: var(--line-strong);
  color: var(--fg);
}

.gallery-cats button.active {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
}

.gallery-cats button.active span {
  color: var(--bg);
  opacity: 0.6;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  align-content: start;
  gap: 12px;
  min-height: 0;
  padding: 4px 20px 40px;
  overflow: auto;
}

.gallery-empty {
  position: absolute;
  top: 180px;
  left: 0;
  right: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.gallery-empty[hidden] {
  display: none;
}

.tpl-card {
  position: relative;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 8px 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease), transform var(--ease);
}

.tpl-card[hidden] {
  display: none;
}

.tpl-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.tpl-card:active {
  transform: scale(0.985);
}

.tpl-card.is-current {
  border-color: var(--fg);
}

.tpl-thumb {
  position: relative;
  display: block;
  height: 168px;
  overflow: hidden;
  border-radius: 9px;
  background: #ffffff;
  pointer-events: none;
}

.tpl-thumb[data-scheme="dark"] {
  background: #212121;
}

.tpl-thumb iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 370px;
  border: 0;
  transform-origin: 0 0;
}

.tpl-thumb::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28px;
  background: linear-gradient(transparent, #ffffff);
}

.tpl-thumb[data-scheme="dark"]::after {
  background: linear-gradient(transparent, #212121);
}

.tpl-meta {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 0 4px;
}

.tpl-meta .tpl-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}

.tpl-meta .tpl-icon .i {
  width: 18px;
  height: 18px;
}

.tpl-meta small {
  display: -webkit-box;
  overflow: hidden;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tpl-card-own {
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  align-content: center;
  min-height: 96px;
  padding: 14px;
  border-style: dashed;
}

.tpl-card-own .tpl-text small {
  white-space: normal;
}

.tpl-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--elevated);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  color: var(--fg-2);
  font-size: 10.5px;
}

/* поле «пары»: две колонки текста в строке */

.pf-head,
.pf-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 28px 28px;
  align-items: center;
  gap: 4px;
}

.pf-head {
  padding: 0 2px;
  color: var(--faint);
  font-size: 11px;
}

.pf-head span:nth-child(2) {
  grid-column: 2;
}

/* ---------- код ---------- */

.wg-code {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.wg-code[hidden] {
  display: none;
}

.code-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 0 14px 10px;
}

.code-note {
  display: grid;
  grid-template-columns: 17px minmax(0, 1fr);
  gap: 8px;
  flex: 1 1 100%;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.code-note .i {
  width: 16px;
  height: 16px;
}

.code-stat {
  margin-left: auto;
  color: var(--faint);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.snippets > summary {
  list-style: none;
}

.snippets > summary::-webkit-details-marker {
  display: none;
}

.code-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.code-gutter {
  min-width: 44px;
  padding: 12px 10px 48px 12px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  color: var(--faint);
  font: 12.5px/20px var(--mono);
  text-align: right;
  white-space: pre;
  user-select: none;
}

#codeInput {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 12px 14px 48px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--fg);
  font: 12.5px/20px var(--mono);
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  caret-color: var(--fg);
}

#codeInput.is-readonly {
  color: var(--fg-2);
}

/* ---------- меню-списки (скачать, сниппеты) ---------- */

.menu-list {
  right: 0;
  left: auto;
  display: grid;
  gap: 1px;
  width: min(320px, calc(100vw - 24px));
  padding: 6px;
}

.snippet-menu {
  left: 0;
  right: auto;
  max-height: 60vh;
  overflow: auto;
}

.menu-list button {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--fg);
  text-align: left;
  transition: background var(--ease);
}

.menu-list button:hover {
  background: var(--surface-3);
}

.menu-list b {
  font-size: 13px;
  font-weight: 500;
}

.menu-list span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.menu-list code {
  overflow: hidden;
  color: var(--faint);
  font: 11.5px var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- превью ---------- */

.wg-preview {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.compact-select {
  height: 30px;
  padding-left: 10px;
  border: 0;
  border-radius: var(--r);
  background-color: var(--surface-3);
  color: var(--fg-2);
  font-size: 12.5px;
}

.sim-options > summary {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r);
  color: var(--muted);
  transition: background var(--ease), color var(--ease);
}

.sim-options > summary:hover,
.sim-options[open] > summary {
  background: var(--surface-3);
  color: var(--fg);
}

.sim-menu {
  min-width: 290px;
  gap: 6px;
}

.sim-menu .field-label {
  padding: 6px 8px 8px;
}

.sim-menu .switch-option input:disabled + span {
  opacity: 0.4;
}

.wg-stage {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: #dfe3e8;
  transition: background var(--ease);
}

.wg-stage[data-scheme="dark"] {
  background: #0e0f11;
}

.wg-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  min-height: 100%;
  padding: 32px 20px 40px;
}

.wg-chat.is-pair {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
}

.wg-viewer {
  display: grid;
  gap: 6px;
  max-width: 100%;
}

.wg-who {
  padding-left: 6px;
  color: rgba(0, 0, 0, 0.55);
  font-size: 12px;
}

.wg-stage[data-scheme="dark"] .wg-who {
  color: rgba(255, 255, 255, 0.5);
}

.wg-bubble {
  max-width: 100%;
  overflow: hidden;
  border-radius: 16px 16px 16px 5px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
  transition: width 180ms ease;
}

.wg-stage[data-scheme="dark"] .wg-bubble {
  background: #212121;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.wg-bubble iframe {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  transition: height 140ms ease;
}

.wg-bubble.is-haptic {
  animation: haptic 120ms ease;
}

@keyframes haptic {
  50% {
    transform: scale(0.985);
  }
}

.wg-fwd {
  padding: 8px 12px 0;
  color: #3390ec;
  font-size: 12.5px;
}

.wg-caption {
  padding: 2px 12px 0;
  color: #000;
  font-size: 14.5px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.wg-stage[data-scheme="dark"] .wg-caption {
  color: #fff;
}

.wg-time {
  padding: 2px 10px 6px;
  color: #9aa3ad;
  font-size: 11px;
  text-align: right;
}

/* ---------- нижняя панель: проверка, журнал, данные ---------- */

.wg-drawer {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 8px 0 10px;
}

.drawer-tabs {
  display: flex;
  gap: 2px;
}

.drawer-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  transition: background var(--ease), color var(--ease);
}

.drawer-tabs button:hover {
  color: var(--fg);
}

.drawer-tabs button.active {
  background: var(--surface-3);
  color: var(--fg);
}

.badge:empty {
  display: none;
}

.badge {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 99px;
  box-shadow: inset 0 0 0 1px var(--line-strong);
  color: var(--fg-2);
  font-size: 10.5px;
  line-height: 18px;
  text-align: center;
}

.badge[data-kind="err"] {
  background: var(--danger);
  box-shadow: none;
  color: #fff;
}

.size-meter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.size-bar {
  position: relative;
  width: 90px;
  height: 4px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--surface-3);
}

.size-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 4px;
  background: var(--fg);
  transition: width 240ms ease, background var(--ease);
}

.size-meter[data-state="warn"] .size-label {
  color: var(--fg);
}

.size-meter[data-state="error"] .size-label {
  color: var(--danger);
}

.size-meter[data-state="error"] .size-bar i {
  background: var(--danger);
}

.drawer-toggle .i {
  transition: transform var(--ease);
}

.wg-drawer.is-collapsed .drawer-toggle .i {
  transform: rotate(180deg);
}

.wg-drawer.is-collapsed .drawer-body {
  display: none;
}

.drawer-body {
  height: 220px;
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.drawer-pane {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px 14px 20px;
}

.drawer-pane[hidden] {
  display: none;
}

.pane-empty {
  padding: 24px 0;
  color: var(--faint);
  font-size: 12.5px;
  text-align: center;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 6px;
  margin-bottom: 6px;
}

.stat-cell {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--r);
  background: var(--surface-2);
}

.stat-cell b {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-cell b small {
  color: var(--faint);
  font-size: 11px;
  font-weight: 400;
}

.stat-cell span {
  color: var(--muted);
  font-size: 11px;
}

.stat-cell.is-over b {
  color: var(--danger);
}

.check-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--fg-2);
  font-size: 12.5px;
  line-height: 1.45;
}

.check-row .i {
  width: 16px;
  height: 16px;
  margin-top: 1px;
}

.check-row.is-err {
  background: var(--danger-soft);
  color: var(--fg);
}

.check-row.is-err .i {
  color: var(--danger);
}

.check-row.is-warn .i {
  color: var(--fg);
}

.check-row.is-ok .i,
.check-row.is-info .i {
  color: var(--muted);
}

.limits {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.limits summary {
  cursor: pointer;
}

.limits ul {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.6;
}

.log-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 10px;
  padding: 5px 8px;
  border-radius: var(--r-sm);
  font: 12px/1.45 var(--mono);
  overflow-wrap: anywhere;
}

.log-row time {
  color: var(--faint);
}

.log-row.is-ok span {
  color: var(--fg);
}

.log-row:not(.is-ok):not(.is-err):not(.is-warn) span {
  color: var(--fg-2);
}

.log-row.is-warn {
  background: var(--surface-2);
}

.log-row.is-err {
  background: var(--danger-soft);
}

.log-row.is-err span {
  color: var(--fg);
}

.data-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.data-block h4 {
  margin: 8px 0 4px;
  font-size: 12.5px;
  font-weight: 500;
}

.data-block h4 small {
  margin-left: 6px;
  color: var(--faint);
  font-weight: 400;
}

.data-block pre {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--fg-2);
  font: 12px/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- модалки и перетаскивание ---------- */

.modal-note {
  margin: 14px 0 0 !important;
  font-size: 12.5px;
}

.dialog-text {
  color: var(--muted);
  line-height: 1.5;
}

.dialog-text p {
  margin: 0 0 8px;
}

.dialog-list {
  margin: 0;
  padding-left: 18px;
  color: var(--fg-2);
  font-size: 13px;
}

.modal-actions [hidden] {
  display: none;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: var(--backdrop);
  backdrop-filter: blur(4px);
  pointer-events: none;
}

.drop-overlay[hidden] {
  display: none;
}

.drop-overlay div {
  padding: 28px 36px;
  border: 1.5px dashed var(--fg);
  border-radius: 16px;
  background: var(--elevated);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  line-height: 1.6;
}

.drop-overlay span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

/* ---------- адаптив ---------- */

@media (max-width: 980px) {
  .widget-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .widget-page .pane {
    height: auto;
  }

  .widget-page .editor-pane {
    height: 78vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .wg-preview {
    min-height: 90vh;
  }

  .wg-stage {
    min-height: 360px;
  }
}

@media (max-width: 700px) {
  .gallery-head {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 14px 12px 8px;
  }

  .gallery-search {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .gallery-cats {
    padding: 0 12px 10px;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
    gap: 8px;
    padding: 4px 12px 32px;
  }

  .tpl-thumb {
    height: 120px;
  }

  .tpl-meta {
    grid-template-columns: minmax(0, 1fr);
  }

  .tpl-meta .tpl-icon {
    display: none;
  }
}

@media (max-width: 540px) {
  .wg-builder {
    padding: 2px 10px 32px;
  }

  .sec-nav {
    margin: 0 -10px;
    padding: 8px 10px;
  }

  .wg-chat {
    padding: 20px 10px 28px;
  }

  .size-bar {
    display: none;
  }

  .drawer-tabs button {
    padding: 0 7px;
  }

  .pane-tools .compact-select {
    max-width: 96px;
  }

  .wg-preview .pane-head > .pane-title {
    display: none;
  }

  .wg-preview .pane-head {
    justify-content: flex-end;
    padding: 0 8px;
  }

  .size-meter .size-label {
    font-size: 11px;
  }
}
