body.preset-editor-open {
  overflow: hidden;
}

.preset-editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(4 8 18 / 72%);
  backdrop-filter: blur(6px);
}

.preset-editor-search-popover {
  z-index: 10060;
}

.exercise-editor-nested-overlay {
  z-index: 10070;
}

.preset-editor-workspace {
  width: min(1480px, 100%);
  height: min(920px, calc(100vh - 36px));
  min-height: 620px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border: 1px solid color-mix(in srgb, var(--rl-preset, #7c3aed) 32%, var(--border-medium));
  border-radius: 20px;
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 30px 100px rgb(0 0 0 / 52%);
  color-scheme: dark;
}

.preset-editor-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  border-bottom: 1px solid color-mix(in srgb, white 7%, transparent);
  background:
    radial-gradient(circle at 82% 20%, rgb(255 255 255 / 10%), transparent 30%),
    linear-gradient(125deg, color-mix(in srgb, var(--rl-preset, #7c3aed) 82%, #17142a), #382657);
  color: #fff;
}

.preset-editor-kicker {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
  opacity: .72;
}

.preset-editor-header h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
}

.preset-editor-header-actions,
.preset-editor-footer,
.preset-editor-footer > div,
.preset-editor-rail-head > div:first-child,
.preset-editor-exercise-tools {
  display: flex;
  align-items: center;
}

.preset-editor-header-actions {
  gap: 12px;
}

.preset-editor-dirty {
  display: none;
  padding: 5px 9px;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 999px;
  background: rgb(20 12 36 / 26%);
  font-size: 11px;
  font-weight: 800;
}

.preset-editor-dirty.is-visible {
  display: inline-flex;
}

.preset-editor-close {
  width: 38px;
  height: 38px;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 11px;
  background: rgb(11 8 24 / 26%);
  color: #fff;
  cursor: pointer;
  font-size: 23px;
  line-height: 1;
}

.preset-editor-meta-toggle {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 9px;
  background: rgb(11 8 24 / 26%);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 800;
}

.preset-editor-meta-toggle:hover,
.preset-editor-meta-toggle:focus-visible {
  border-color: rgb(255 255 255 / 46%);
  background: rgb(11 8 24 / 42%);
}

.preset-editor-meta {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, .55fr);
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-surface-raised);
}

.preset-editor-meta label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.preset-editor-meta-wide {
  grid-column: 1 / -1;
}

.preset-editor-meta input,
.preset-editor-search input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-medium);
  border-radius: 9px;
  outline: none;
  background: var(--bg-input, var(--bg-surface));
  color: var(--text-primary);
  font: inherit;
}

.preset-editor-meta input {
  min-height: 38px;
  padding: 8px 11px;
}

.preset-editor-meta input:focus,
.preset-editor-search input:focus {
  border-color: var(--rl-preset, #7c3aed);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rl-preset, #7c3aed) 14%, transparent);
}

.preset-editor-main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(236px, 276px) minmax(0, 1fr);
}

.preset-editor-rail {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--border-light);
  background: color-mix(in srgb, var(--bg-surface-raised) 74%, var(--bg-surface));
}

.preset-editor-rail-head {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border-light);
}

.preset-editor-rail-head > div:first-child {
  justify-content: space-between;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.preset-editor-rail-head strong {
  min-width: 26px;
  padding: 3px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--rl-preset, #7c3aed) 14%, transparent);
  color: var(--rl-preset, #a78bfa);
  text-align: center;
}

.preset-editor-search {
  position: relative;
}

.preset-editor-search input {
  min-height: 39px;
  padding: 9px 11px;
}

.preset-editor-search-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 310px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--border-medium);
  border-radius: 11px;
  background: var(--bg-surface);
  box-shadow: 0 18px 44px rgb(0 0 0 / 40%);
}

.preset-editor-search-popover button {
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}

.preset-editor-search-popover button:hover {
  background: color-mix(in srgb, var(--rl-preset, #7c3aed) 12%, transparent);
}

.preset-editor-search-popover button span,
.preset-editor-search-empty {
  color: var(--text-muted);
  font-size: 11px;
}

.preset-editor-search-empty {
  display: block;
  padding: 10px;
}

.preset-editor-exercise-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 12px;
  scrollbar-width: thin;
}

.preset-editor-exercise {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  background: var(--bg-surface);
  overflow: hidden;
}

.preset-editor-exercise.is-active {
  border-color: color-mix(in srgb, var(--rl-preset, #7c3aed) 70%, var(--border-medium));
  box-shadow: inset 3px 0 var(--rl-preset, #7c3aed);
}

/* Superset, giant set e pre-affaticamento: il collegato sta sotto al principale e si
   legge come un blocco unico, con lo stesso ciano delle sub-row del builder
   (.exercise-sub-row--linked-ex in css/training-cards.css). Prima galleggiava nella
   lista come un esercizio qualsiasi e il giro non si vedeva. */
.preset-editor-exercise-group {
  display: grid;
  gap: 4px;
}

.preset-editor-exercise--has-linked {
  border-color: color-mix(in srgb, #06b6d4 34%, var(--border-light));
}

.preset-editor-exercise--linked {
  position: relative;
  margin-left: 18px;
  /* Il gancio esce dal bordo sinistro: con overflow:hidden verrebbe tagliato. */
  overflow: visible;
  border-color: color-mix(in srgb, #06b6d4 30%, var(--border-light));
  background:
    linear-gradient(90deg,
      color-mix(in srgb, #06b6d4 10%, var(--bg-surface)) 0%,
      var(--bg-surface) 46%);
}

.preset-editor-exercise--linked::before,
.preset-editor-exercise--linked::after {
  content: "";
  position: absolute;
  background: color-mix(in srgb, #06b6d4 52%, var(--border-medium));
  pointer-events: none;
}

.preset-editor-exercise--linked::before {
  left: -10px;
  top: -6px;
  bottom: 50%;
  width: 2px;
  border-radius: 999px 999px 0 0;
}

/* Pre-affaticamento: l'isolamento sta SOPRA il multiarticolare, quindi il gancio
   scende verso il principale invece di salire verso di lui. */
.preset-editor-exercise--linked-up::before {
  top: 50%;
  bottom: -6px;
  border-radius: 0 0 999px 999px;
}

.preset-editor-exercise--linked::after {
  left: -10px;
  top: calc(50% - 1px);
  width: 10px;
  height: 2px;
  border-radius: 0 999px 999px 0;
}

.preset-editor-exercise-index--linked {
  background: color-mix(in srgb, #06b6d4 16%, transparent);
  color: #06b6d4;
  font-size: 12px;
}

.preset-editor-exercise--linked .preset-editor-exercise-copy span {
  color: #06b6d4;
  font-weight: 800;
}

.preset-editor-exercise-select {
  min-width: 0;
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 11px 4px 11px 11px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}

.preset-editor-exercise-index {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: color-mix(in srgb, var(--rl-preset, #7c3aed) 14%, transparent);
  color: var(--rl-preset, #a78bfa);
  font-size: 11px;
  font-weight: 900;
}

.preset-editor-exercise-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.preset-editor-exercise-copy small,
.preset-editor-exercise-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Il nome e' l'unica cosa che serve leggere per intero: nella rail piu' stretta va
   a capo invece di troncare, fino a due righe. */
.preset-editor-exercise-copy strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.25;
}

.preset-editor-exercise-copy small,
.preset-editor-exercise-copy span {
  color: var(--text-muted);
  font-size: 10px;
}

.preset-editor-exercise-tools {
  gap: 2px;
  padding-right: 7px;
}

.preset-editor-exercise-tools button {
  width: 25px;
  height: 25px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.preset-editor-exercise-tools button:hover:not(:disabled) {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
}

.preset-editor-exercise-tools button:last-child:hover {
  color: var(--danger, #ef4444);
}

.preset-editor-exercise-tools button:disabled {
  opacity: .25;
  cursor: default;
}

.preset-editor-empty,
.preset-editor-editor-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  min-height: 160px;
  padding: 24px;
  color: var(--text-secondary);
  text-align: center;
}

.preset-editor-empty span,
.preset-editor-editor-empty span {
  color: var(--text-muted);
  font-size: 12px;
}

.preset-editor-editor {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  background: var(--bg-surface);
}

.preset-editor-editor > [data-preset-exercise-editor-host] {
  height: 100%;
}

.preset-editor-footer {
  min-height: 66px;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-surface-raised);
}

.preset-editor-footer > span {
  color: var(--text-muted);
  font-size: 11px;
}

.preset-editor-footer > div {
  gap: 9px;
}

.preset-editor-load-error {
  color: var(--danger, #ef4444);
}

/* Prescrizione preset: condivide le card parametro del drawer, ma sul workspace
   largo mantiene il rapporto volume a sinistra / esecuzione e target a destra. */
.preset-editor-editor .pbd-sec--prescription .pbd-presc-list--split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: flex-start;
  column-gap: 22px;
  row-gap: 0;
}

.preset-editor-editor .pbd-sec--prescription .pbd-presc-col {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preset-editor-editor .pbd-sec--prescription .pbd-presc-col--side {
  padding-left: 0;
  border-left: 0;
}

/* Nel preset ogni card occupa esattamente la colonna: il separatore e' lo spazio
   tra le due colonne, non una sottrazione di larghezza alla colonna destra. */
.preset-editor-editor .pbd-sec--prescription .pbd-presc-col > .pbd-presc-row {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Le card rimangono verticali anche nel preset: la differenza rispetto al drawer
   e' solo la divisione in due colonne del pannello, non una seconda grammatica
   label/controllo. */
.preset-editor-editor .pbd-sec--prescription .pbd-presc-col > .pbd-presc-row:not(.pbd-presc-intensity-row) {
  grid-template-columns: none;
  gap: 12px;
}

.preset-editor-editor .pbd-sec--prescription .pbd-presc-col .pbd-label-sub {
  max-width: none;
}

.preset-editor-editor .pbd-sec--prescription .pbd-presc-intensity-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.preset-editor-editor .pbd-sec--prescription .reps-range-wrap--prescription .pbd-unit-segment {
  width: min(148px, 100%);
}

/* Il titolo dell'esercizio e il suo tag restano nella stessa riga: il drawer
   della scheda non eredita queste regole, che vivono solo nel workspace preset. */
.preset-editor-editor [data-exercise-editor-root] .pb-drawer-head,
.preset-editor-editor [data-exercise-editor-root] .pbd-head-txt {
  flex-wrap: nowrap;
}

.preset-editor-editor [data-exercise-editor-root] .pbd-head-txt .pb-drawer-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-editor-editor [data-exercise-editor-root] .pbd-head-txt .pb-tag {
  flex: 0 0 auto;
}

/* Con il pannello largo due colonne di parametri sono enormi: a schermo pieno ne
   stanno tre senza stringere niente. */
@media (min-width: 1240px) {
  .preset-editor-editor [data-exercise-editor-root] .exercise-editor-tech-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .preset-editor-editor .pbd-sec--prescription .pbd-presc-list--split {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .preset-editor-editor .pbd-sec--prescription .pbd-presc-col--side {
    padding-left: 0;
    border-left: none;
  }

}

@media (max-width: 980px) {
  .preset-editor-overlay {
    padding: 8px;
  }

  .preset-editor-workspace {
    height: calc(100vh - 16px);
    min-height: 0;
    border-radius: 15px;
  }

  .preset-editor-main {
    overflow: auto;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(230px, 38vh) minmax(520px, auto);
  }

  .preset-editor-rail {
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }

  .preset-editor-editor {
    min-height: 520px;
  }
}

@media (max-width: 620px) {
  .preset-editor-meta {
    grid-template-columns: 1fr;
  }

  .preset-editor-meta-wide {
    grid-column: auto;
  }

  .preset-editor-dirty {
    max-width: 104px;
  }

  .preset-editor-footer > span {
    display: none;
  }

  .preset-editor-footer {
    justify-content: flex-end;
  }
}
