/* ==========================================================================
   Field placement editor
   ========================================================================== */

.ed {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: 52px 40px minmax(0, 1fr);
  background: var(--bg-app);
  overflow: hidden;
}

/* --------------------------------------------------------------- top bar */
.ed-top {
  display: flex; align-items: center; gap: var(--s-5);
  padding: 0 var(--s-7) 0 var(--s-4);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--br-1);
  min-width: 0;
}
.ed-title { min-width: 0; max-width: 30vw; }
.ed-title__name { font-size: var(--fs-14); font-weight: 600; letter-spacing: -.01em; display: block; }

.ed-steps { display: flex; align-items: center; gap: var(--s-3); margin-left: var(--s-8); }
.ed-step {
  display: inline-flex; align-items: center; gap: var(--s-4);
  height: 28px; padding: 0 var(--s-5);
  border-radius: var(--r-pill);
  font-size: var(--fs-12); font-weight: 540; color: var(--tx-3);
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}
.ed-step:hover { background: var(--bg-hover); color: var(--tx-1); }
.ed-step__n {
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-content: center;
  font-size: 10px; font-weight: 700;
  background: var(--n-100); color: var(--tx-3);
}
.ed-step.is-done .ed-step__n { background: var(--ok-50); color: var(--ok-500); }
.ed-step.is-cur { background: var(--bg-selected); color: var(--tx-accent); font-weight: 620; }
.ed-step.is-cur .ed-step__n { background: var(--a-500); color: #fff; }

/* --------------------------------------------------------------- tool bar */
.ed-bar {
  display: flex; align-items: center; gap: var(--s-4);
  padding: 0 var(--s-6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--br-1);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
}
.ed-bar::-webkit-scrollbar { display: none; }
.ed-bar__group { display: flex; align-items: center; gap: 1px; flex: none; }
.ed-bar .vdivider { height: 20px; margin-inline: var(--s-2); }

/* ----------------------------------------------------------------- body */
.ed-body {
  display: grid;
  grid-template-columns: 0 234px minmax(0, 1fr) 0;
  min-height: 0;
}
.ed.is-thumbs .ed-body { grid-template-columns: 112px 234px minmax(0, 1fr) 0; }
.ed.is-props .ed-body { grid-template-columns: 0 234px minmax(0, 1fr) 286px; }
.ed.is-thumbs.is-props .ed-body { grid-template-columns: 112px 234px minmax(0, 1fr) 286px; }

.ed-thumbs { min-width: 0; overflow: hidden; }
.ed-thumbs .thumbs { height: 100%; }
.ed-main { min-width: 0; display: flex; flex-direction: column; position: relative; }
.ed-canvas { flex: 1 1 auto; min-height: 0; display: flex; }
.ed-canvas .dv { width: 100%; }

/* --------------------------------------------------------------- palette */
.ed-palette {
  border-left: 1px solid var(--br-1);
  border-right: 1px solid var(--br-1);
  background: var(--bg-surface);
  display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
}
.ed-palette__head { padding: var(--s-7) var(--s-6) var(--s-6); border-bottom: 1px solid var(--br-1); }
.ed-recip {
  display: flex; align-items: center; gap: var(--s-5);
  width: 100%; margin-top: var(--s-4); padding: var(--s-4) var(--s-5);
  border: 1px solid var(--br-2); border-radius: var(--r-8);
  background: var(--rc-soft, var(--bg-sunken));
  border-left: 3px solid var(--rc-bd, var(--br-3));
  transition: border-color var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}
.ed-recip:hover { border-color: var(--br-3); }
.ed-recip__name { font-size: var(--fs-13); font-weight: 570; }
.ed-palette__nosigner {
  display: flex; flex-direction: column; gap: var(--s-5); align-items: flex-start;
  margin-top: var(--s-4); padding: var(--s-6);
  background: var(--warn-50); border: 1px solid var(--warn-100); border-radius: var(--r-8);
}

.ed-autoplace { padding: var(--s-6); border-bottom: 1px solid var(--br-1); }
.ed-palette__scroll { flex: 1 1 auto; overflow-y: auto; padding: var(--s-6); }

.ed-group + .ed-group { margin-top: var(--s-8); }
.ed-group__label {
  font-size: var(--fs-11); font-weight: 620; color: var(--tx-4);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: var(--s-4);
}
.ed-group__items { display: flex; flex-direction: column; gap: var(--s-3); }

.ed-pitem {
  display: flex; align-items: center; gap: var(--s-5);
  height: 32px; padding: 0 var(--s-4) 0 var(--s-3);
  border: 1px solid var(--br-1); border-radius: var(--r-6);
  background: var(--bg-surface);
  font-size: var(--fs-12); color: var(--tx-1);
  cursor: grab; text-align: left;
  transition: border-color var(--dur-2) var(--ease), background var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
  touch-action: none;
}
.ed-pitem:hover { border-color: var(--rc-bd, var(--a-400)); background: var(--rc-soft, var(--a-25)); }
.ed-pitem:active { cursor: grabbing; }
.ed-pitem.is-armed {
  border-color: var(--rc-bd, var(--a-500));
  background: var(--rc-fill, var(--a-50));
  box-shadow: 0 0 0 1px var(--rc-bd, var(--a-500));
  font-weight: 600;
}
.ed-pitem__ic {
  width: 24px; height: 24px; border-radius: var(--r-4); flex: none;
  display: grid; place-content: center;
  background: var(--rc-fill, var(--bg-sunken));
  color: var(--rc-ink, var(--tx-2));
}
.ed-pitem__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-pitem__grip { color: var(--tx-4); opacity: 0; transition: opacity var(--dur-2) var(--ease); }
.ed-pitem:hover .ed-pitem__grip { opacity: 1; }
.ed-pitem__armed { color: var(--rc-bd, var(--a-600)); }

.ed-cover {
  display: flex; align-items: center; gap: var(--s-5);
  width: 100%; padding: var(--s-4) var(--s-5);
  border-radius: var(--r-6); font-size: var(--fs-12); text-align: left;
  transition: background var(--dur-1) var(--ease);
}
.ed-cover:hover { background: var(--bg-hover); }
.ed-cover__warn { color: var(--warn-500); }
.ed-warn {
  display: flex; gap: var(--s-4); align-items: flex-start;
  margin-top: var(--s-5); padding: var(--s-5);
  background: var(--warn-50); border: 1px solid var(--warn-100);
  border-radius: var(--r-6); font-size: var(--fs-11); color: var(--tx-2); line-height: 1.45;
}
.ed-warn svg { color: var(--warn-500); flex: none; margin-top: 1px; }

/* ------------------------------------------------------------ properties */
.ed-props {
  border-left: 1px solid var(--br-1);
  background: var(--bg-surface);
  min-width: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
.ed-props__empty {
  padding: var(--s-10) var(--s-8);
  display: flex; flex-direction: column; gap: var(--s-4);
  text-align: left;
}
.ed-props__inner { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.ed-props__head {
  display: flex; align-items: center; gap: var(--s-5);
  padding: var(--s-6) var(--s-7);
  border-bottom: 1px solid var(--br-1);
  flex: none;
}
.ed-props__ic {
  width: 28px; height: 28px; border-radius: var(--r-6); flex: none;
  display: grid; place-content: center;
  background: var(--rc-fill, var(--bg-sunken));
  color: var(--rc-ink, var(--tx-2));
}
.ed-props__scroll { flex: 1 1 auto; overflow-y: auto; padding: var(--s-7); }

.ed-sec + .ed-sec { margin-top: var(--s-9); padding-top: var(--s-8); border-top: 1px solid var(--br-1); }
.ed-sec { display: flex; flex-direction: column; gap: var(--s-6); }
.ed-sec__label {
  font-size: var(--fs-11); font-weight: 620; color: var(--tx-4);
  text-transform: uppercase; letter-spacing: .06em;
}
.ed-grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); }
.ed-num { display: flex; flex-direction: column; gap: 3px; }
.ed-num__l { font-size: var(--fs-11); color: var(--tx-3); font-weight: 600; }
.ed-num input { text-align: center; padding-inline: 2px; }
.ed-alignbtns { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.ed-alignbtns .btn { justify-content: flex-start; }

/* --------------------------------------------------------------- fields */
.ed-f {
  position: absolute;
  box-sizing: border-box;
  border: 1.5px solid var(--rc-bd);
  background: color-mix(in srgb, var(--rc-fill) 78%, transparent);
  border-radius: 2px;
  cursor: grab;
  display: flex; align-items: center;
  overflow: visible;
  transition: box-shadow var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
  user-select: none;
}
.ed-f:hover { background: var(--rc-fill); box-shadow: 0 0 0 2px color-mix(in srgb, var(--rc-bd) 30%, transparent); }
.ed-f:focus-visible { outline: 2px solid var(--a-500); outline-offset: 1px; }
.ed-f.is-selected {
  background: var(--rc-fill);
  box-shadow: 0 0 0 1.5px var(--rc-bd), 0 2px 8px rgba(16,24,40,.16);
  z-index: 3;
}
.ed-f.is-other { opacity: .5; }
.ed-f.is-other:hover { opacity: .78; }
.ed-f.is-locked { cursor: not-allowed; }
.ed-f__inner {
  display: flex; align-items: center; gap: 3px;
  padding: 0 3px; min-width: 0; width: 100%;
  color: var(--rc-ink);
  font-size: 10px; font-weight: 600; line-height: 1;
  pointer-events: none;
}
.ed-f__ic { flex: none; }
.ed-f__label { min-width: 0; }
.ed-f__req {
  position: absolute; top: -6px; right: -3px;
  color: var(--err-500); font-size: 13px; font-weight: 800; line-height: 1;
  pointer-events: none;
}
.ed-f__cond { position: absolute; bottom: -6px; right: -4px; color: var(--plum-500); background: var(--bg-surface); border-radius: 50%; display: grid; place-content: center; width: 13px; height: 13px; }
.ed-f__lock { position: absolute; top: -5px; left: -5px; color: var(--tx-3); background: var(--bg-surface); border-radius: 50%; width: 13px; height: 13px; display: grid; place-content: center; }
.ed-f__badge {
  position: absolute; left: -1.5px; bottom: calc(100% + 3px);
  padding: 1px 5px; border-radius: 3px;
  background: var(--rc-bd); color: #fff;
  font-size: 9.5px; font-weight: 650; white-space: nowrap;
  pointer-events: none;
}
.ed-f__h {
  position: absolute; width: 8px; height: 8px;
  background: var(--bg-surface);
  border: 1.5px solid var(--rc-bd);
  border-radius: 2px;
  z-index: 4;
}
.ed-f__h--nw { top: -5px; left: -5px; cursor: nw-resize; }
.ed-f__h--n  { top: -5px; left: 50%; margin-left: -4px; cursor: n-resize; }
.ed-f__h--ne { top: -5px; right: -5px; cursor: ne-resize; }
.ed-f__h--e  { top: 50%; right: -5px; margin-top: -4px; cursor: e-resize; }
.ed-f__h--se { bottom: -5px; right: -5px; cursor: se-resize; }
.ed-f__h--s  { bottom: -5px; left: 50%; margin-left: -4px; cursor: s-resize; }
.ed-f__h--sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.ed-f__h--w  { top: 50%; left: -5px; margin-top: -4px; cursor: w-resize; }

.dv__layer.is-armed { cursor: copy; }
.dv__layer.is-armed .ed-f { cursor: copy; }

.ed-guides { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.ed-guide { position: absolute; background: #e0397a; }
.ed-guide--v { top: 0; bottom: 0; width: 1px; }
.ed-guide--h { left: 0; right: 0; height: 1px; }

.ed-marquee {
  position: absolute;
  border: 1px solid var(--a-500);
  background: color-mix(in srgb, var(--a-500) 12%, transparent);
  border-radius: 2px; pointer-events: none; z-index: 7;
}

.ed-ghosts { position: fixed; inset: 0; pointer-events: none; z-index: var(--z-drag); }
.ed-ghost {
  position: absolute; top: 0; left: 0;
  display: flex; align-items: center; gap: 4px; padding: 0 5px;
  border: 1.5px solid var(--rc-bd, var(--a-500));
  background: var(--rc-fill, var(--a-50));
  color: var(--rc-ink, var(--a-800));
  border-radius: 2px;
  font-size: 10px; font-weight: 650;
  box-shadow: var(--sh-md);
  opacity: .92;
  margin: -12px 0 0 -34px;
  white-space: nowrap;
}
.ed-ghost.is-over { opacity: 1; box-shadow: var(--sh-lg); }

.ed.is-moving .dv__scroll, .ed.is-resizing .dv__scroll { scroll-behavior: auto; }

/* ---------------------------------------------------------------- preview */
.ed-preview { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ed-preview__bar {
  display: flex; align-items: center; gap: var(--s-5);
  padding: var(--s-5) var(--s-8);
  border-bottom: 1px solid var(--br-1);
  background: var(--bg-sunken);
  flex: none;
}
.ed-preview__body { flex: 1 1 auto; min-height: 0; display: flex; }
.ed-pf {
  position: absolute; box-sizing: border-box;
  display: flex; align-items: center;
  border-radius: 2px; overflow: hidden;
  font-family: var(--font-sans);
}
.ed-pf.is-mine {
  background: #fff6d8; border: 1px solid #e2c15f;
  box-shadow: 0 1px 2px rgba(16,24,40,.14);
}
.ed-pf.is-other { background: color-mix(in srgb, var(--rc-fill) 42%, transparent); border: 1px dashed var(--rc-bd); opacity: .5; }
.ed-pf__tab {
  display: inline-flex; align-items: center; gap: 3px;
  height: 100%; padding: 0 6px;
  background: #ffc832; color: #3a2c00;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.ed-pf__ph { padding: 0 4px; color: #8a7a45; font-size: inherit; }
.ed-pf__box { width: 11px; height: 11px; margin: 0 3px; border: 1.2px solid #8a7a45; border-radius: 2px; }
.ed-pf__radio { width: 9px; height: 9px; border: 1.2px solid #8a7a45; border-radius: 50%; flex: none; }
.ed-pf__sel { display: inline-flex; align-items: center; gap: 4px; padding: 0 4px; color: #6b5c2e; font-size: inherit; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1320px) {
  .ed.is-props .ed-body { grid-template-columns: 0 214px minmax(0, 1fr) 262px; }
  .ed.is-thumbs.is-props .ed-body { grid-template-columns: 96px 214px minmax(0, 1fr) 262px; }
  .ed.is-thumbs .ed-body { grid-template-columns: 96px 214px minmax(0, 1fr) 0; }
  .ed-title { max-width: 22vw; }
}
@media (max-width: 1080px) {
  .ed-hide-sm { display: none; }
  .ed-steps { display: none; }
  .ed-body,
  .ed.is-thumbs .ed-body,
  .ed.is-props .ed-body,
  .ed.is-thumbs.is-props .ed-body { grid-template-columns: 0 208px minmax(0, 1fr) 0; }
  .ed-props {
    position: fixed; right: 0; top: 92px; bottom: 0; width: 288px;
    z-index: 30; box-shadow: var(--sh-lg);
    transform: translateX(102%);
    transition: transform var(--dur-3) var(--ease-out);
  }
  .ed.is-props .ed-props { transform: none; }
}
@media (max-width: 760px) {
  .ed { grid-template-rows: 50px 40px minmax(0, 1fr); }
  .ed-body, .ed.is-thumbs .ed-body, .ed.is-props .ed-body, .ed.is-thumbs.is-props .ed-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "main";
  }
  .ed-body > .ed-main { grid-area: main; }
  .ed-palette { grid-area: main; }
  .ed-thumbs { display: none; }
  .ed-palette {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: 46vh; z-index: 32;
    border-top: 1px solid var(--br-2); border-left: 0; border-right: 0;
    border-radius: var(--r-16) var(--r-16) 0 0;
    box-shadow: var(--sh-xl);
    transform: translateY(calc(100% - 46px));
    transition: transform var(--dur-4) var(--ease-out);
  }
  .ed-palette::before {
    content: "Fields";
    display: block; text-align: center; padding: var(--s-4);
    font-size: var(--fs-12); font-weight: 620; color: var(--tx-2);
    border-bottom: 1px solid var(--br-1);
  }
  .ed-palette:focus-within, .ed-palette:hover { transform: none; }
  .ed-props { top: 90px; width: 100%; }
  .ed-title { max-width: 40vw; }
  .ed-num__l { font-size: 10px; }
}
