/* IDEFO КПД v22 — единая координатная модель редактора и печати. */

:root {
  --idefo-a4-width: 297mm;
  --idefo-a4-height: 210mm;
  --idefo-canvas-width-mm: 285;
  --idefo-canvas-height-mm: 171;
}

/* Свободные области размещаются над всей рабочей зоной листа. */
.sheet-page:not(.cover-page) .sketch {
  overflow: visible !important;
}

.sheet-page:not(.cover-page) .view-grid {
  overflow: hidden !important;
}

.free-frame-layer {
  inset: 0 !important;
  z-index: 45 !important;
  overflow: visible !important;
  pointer-events: none;
}

.sheet-page:not(.without-spec) .sketch > .free-frame-layer {
  right: auto !important;
  width: calc(142.857% + 8px) !important;
  max-width: none !important;
}

.free-image-frame {
  position: absolute;
  display: block;
  min-width: 24px;
  min-height: 24px;
  overflow: visible !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  cursor: move;
  pointer-events: auto;
  touch-action: none;
  transform-origin: 50% 50%;
}

.free-frame-visual {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  box-sizing: border-box;
  border: 1.5px dashed #b79114;
  background: rgb(248 248 244 / 92%);
  box-shadow: 0 2px 10px rgb(0 0 0 / 10%);
}

.free-shape-ellipse .free-frame-visual {
  border-radius: 50%;
}

.free-image-frame.has-image .free-frame-visual {
  background: #fff;
}

.free-image-frame.selected .free-frame-visual {
  border-style: solid;
  border-color: #d1a000;
  outline: 2px solid rgb(255 219 78 / 72%);
  outline-offset: 2px;
  box-shadow: 0 5px 22px rgb(0 0 0 / 22%);
}

.free-frame-visual > img,
.print-free-image-frame .free-frame-visual > img {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none !important;
  user-select: none !important;
  -webkit-user-drag: none !important;
}

.free-frame-add {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  color: #60562e;
  background: transparent;
  font-size: clamp(9px, 1.4cqw, 14px);
  font-weight: 900;
  cursor: pointer;
}

/* Крупные маркеры и ещё более крупные невидимые зоны захвата. */
.free-frame-handle {
  position: absolute;
  z-index: 80;
  width: 15px;
  height: 15px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #d1a000;
  box-shadow: 0 1px 5px rgb(0 0 0 / 32%);
}

.free-frame-handle::before {
  content: "";
  position: absolute;
  inset: -13px;
  border-radius: 50%;
}

.free-frame-handle.west { left: 0; top: 50%; transform: translate(-50%, -50%); cursor: ew-resize; }
.free-frame-handle.east { left: 100%; top: 50%; transform: translate(-50%, -50%); cursor: ew-resize; }
.free-frame-handle.north { left: 50%; top: 0; transform: translate(-50%, -50%); cursor: ns-resize; }
.free-frame-handle.south { left: 50%; top: 100%; transform: translate(-50%, -50%); cursor: ns-resize; }
.free-frame-handle.north-west { left: 0; top: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
.free-frame-handle.north-east { left: 100%; top: 0; transform: translate(-50%, -50%); cursor: nesw-resize; }
.free-frame-handle.south-east { left: 100%; top: 100%; transform: translate(-50%, -50%); cursor: nwse-resize; }
.free-frame-handle.south-west { left: 0; top: 100%; transform: translate(-50%, -50%); cursor: nesw-resize; }

.free-shape-ellipse .free-frame-handle.south-east {
  width: 18px;
  height: 18px;
  background: #435260;
}

.free-frame-rotate {
  position: absolute;
  z-index: 85;
  left: 50%;
  top: -45px;
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #33404c;
  box-shadow: 0 2px 7px rgb(0 0 0 / 34%);
  transform: translateX(-50%);
  cursor: grab;
  touch-action: none;
}

.free-frame-rotate::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 26px;
  background: #33404c;
  transform: translateX(-50%);
}

.free-frame-rotate::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
}

/* Компактная панель непосредственно над выбранным объектом. */
.free-frame-toolbar {
  position: absolute;
  z-index: 100;
  left: 50%;
  bottom: calc(100% + 58px);
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: min(520px, 92vw);
  padding: 4px;
  border: 1px solid rgb(0 0 0 / 16%);
  border-radius: 9px;
  background: rgb(255 255 255 / 97%);
  box-shadow: 0 7px 24px rgb(0 0 0 / 22%);
  transform: translateX(-50%);
  white-space: nowrap;
}

.free-frame-toolbar button {
  min-height: 27px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  color: #282a24;
  background: transparent;
  font-size: 9px;
  font-weight: 850;
  cursor: pointer;
}

.free-frame-toolbar button:hover,
.free-frame-toolbar button:focus-visible {
  background: #f1f3ea;
}

.free-frame-toolbar button.danger {
  color: #a82f29;
}

.free-frame-label {
  position: absolute;
  z-index: 55;
  max-width: 94%;
  padding: .14em .36em;
  overflow: hidden;
  border-radius: 3px;
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  text-overflow: ellipsis;
  text-shadow: 0 0 2px #fff, 0 0 5px #fff;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  cursor: move;
  pointer-events: auto !important;
  user-select: none;
}

/* Радиальное меню по правой кнопке мыши. */
.free-frame-radial {
  position: absolute;
  z-index: 130;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.free-frame-radial::before {
  content: "";
  position: absolute;
  left: -27px;
  top: -27px;
  width: 54px;
  height: 54px;
  border: 1px solid rgb(0 0 0 / 14%);
  border-radius: 50%;
  background: rgb(255 255 255 / 96%);
  box-shadow: 0 8px 30px rgb(0 0 0 / 24%);
}

.free-frame-radial button {
  --radius: 54px;
  position: absolute;
  left: -16px;
  top: -16px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid #d8d9d2;
  border-radius: 50%;
  color: #2a2b26;
  background: #fff;
  box-shadow: 0 2px 8px rgb(0 0 0 / 18%);
  font-size: 10px;
  font-weight: 900;
  transform: rotate(var(--a)) translateX(var(--radius));
  cursor: pointer;
  pointer-events: auto;
}

.free-frame-radial button:hover {
  border-color: #d2a400;
  background: #fff6c8;
}

.free-frame-radial button.danger {
  color: #aa3028;
  border-color: #efc4c0;
}

.free-frame-settings .form-grid input[type="number"] {
  font-variant-numeric: tabular-nums;
}

.zoom-reset {
  min-width: 51px;
  padding-inline: 7px !important;
  font-weight: 900;
}

/* Нижняя рамка: основная свободная ширина отдаётся заказчику. */
.sheet-page footer {
  grid-template-columns: minmax(205px, 22%) minmax(0, 1fr) minmax(290px, 29%) 60px !important;
}

.sheet-page footer > div {
  min-width: 0;
}

.approval-row {
  grid-template-columns: minmax(0, 1fr) minmax(72px, .72fr) minmax(82px, .82fr) !important;
  gap: 5px !important;
}

.approval-row > span,
.approval-row small {
  text-overflow: clip !important;
}

/* Печать строится из одного A4-макета и масштабируется целиком. */
.print-album {
  --print-page-padding: 6mm !important;
  --print-spec-width: 67mm !important;
  --print-header-height: 8mm !important;
  --print-footer-height: 16mm !important;
  --print-gap: 1.5mm !important;
  --print-heading-pad: 52mm !important;
  --print-heading-font: 16pt !important;
}

.preview-open .print-page {
  width: var(--idefo-a4-width) !important;
  min-width: var(--idefo-a4-width) !important;
  max-width: var(--idefo-a4-width) !important;
  height: var(--idefo-a4-height) !important;
  min-height: var(--idefo-a4-height) !important;
  max-height: var(--idefo-a4-height) !important;
  zoom: var(--preview-total-scale, var(--paper-scale, 1));
  transform: none !important;
}

.print-view-grid {
  position: relative !important;
  overflow: visible !important;
}

.print-view-grid > div:not(.print-free-frame-layer) {
  overflow: hidden;
}

.print-view-grid > .print-free-frame-layer {
  position: absolute !important;
  z-index: 70 !important;
  inset: 0 !important;
  display: block !important;
  overflow: visible !important;
  border: 0 !important;
  background: transparent !important;
  pointer-events: none !important;
}

.print-sheet:not(.print-no-spec) .print-view-grid > .print-free-frame-layer {
  right: auto !important;
  width: calc(100% + var(--print-spec-width) + var(--print-gap)) !important;
}

.print-free-image-frame {
  position: absolute !important;
  display: block !important;
  overflow: visible !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.print-free-image-frame .free-frame-visual {
  border: 0 !important;
  outline: 0 !important;
  box-shadow: none !important;
}

.print-sheet > footer {
  grid-template-columns: 22% minmax(0, 1fr) 29% 7% !important;
  gap: 0 !important;
}

.print-album[data-paper-format="A3"] .print-sheet > footer {
  grid-template-columns: 19% minmax(0, 1fr) 26% 6% !important;
}

.print-album[data-paper-format="A5"] .print-sheet > footer {
  grid-template-columns: 24% minmax(0, 1fr) 29% 8% !important;
}

.print-sheet > footer > span {
  min-width: 0;
  padding: .9mm 1.4mm !important;
  overflow: hidden;
  text-align: left !important;
}

.print-approval {
  display: grid !important;
  grid-template-rows: 1fr 1fr;
  gap: 0 !important;
  padding: 0 !important;
}

.print-approval > span {
  min-width: 0;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 25mm 30mm !important;
  align-items: center;
  gap: .7mm !important;
  padding: .55mm 1mm !important;
}

.print-approval > span + span {
  border-top: .2mm solid #999;
}

.print-approval b,
.print-approval small {
  overflow: visible !important;
  color: #111 !important;
  text-overflow: clip !important;
  white-space: nowrap !important;
}

.print-approval b {
  font-size: 5.5pt !important;
}

.print-approval small {
  font-size: 4.8pt !important;
}

.print-project-page {
  display: grid !important;
  place-content: center;
  justify-items: center;
  gap: 0 !important;
  padding: .4mm !important;
  text-align: center !important;
}

.print-project-page small {
  font-size: 5pt !important;
  line-height: 1.02;
}

.print-project-page strong {
  margin-top: .45mm;
  font-size: 8.5pt !important;
  line-height: 1;
  white-space: nowrap;
}

.print-color-warning {
  right: .8mm !important;
  font-size: 5pt !important;
}

.print-approval-disclaimer {
  right: 27% !important;
  bottom: .8mm !important;
  font-size: 4.5pt !important;
}

.print-sheet .print-credit {
  bottom: .8mm !important;
  font-size: 4.3pt !important;
}

@media print {
  .free-frame-toolbar,
  .free-frame-radial,
  .free-frame-handle,
  .free-frame-rotate,
  .free-frame-add {
    display: none !important;
  }

  .print-page {
    width: var(--idefo-a4-width) !important;
    min-width: var(--idefo-a4-width) !important;
    max-width: var(--idefo-a4-width) !important;
    height: var(--idefo-a4-height) !important;
    min-height: var(--idefo-a4-height) !important;
    max-height: var(--idefo-a4-height) !important;
    zoom: var(--paper-scale, 1) !important;
    transform: none !important;
  }

  .print-free-image-frame,
  .print-free-image-frame img,
  .print-free-image-frame .free-frame-label {
    visibility: visible !important;
    opacity: 1 !important;
  }
}
