/* Печать и PDF страницы объекта: кнопки, окно выбора фото и печатный лист.
   Подключается только на property.html (вставляет server.mjs). */

.property-doc-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.property-doc-actions .btn {
  gap: 8px;
}

.property-doc-actions svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Окно выбора фото */
.print-dialog {
  /* Общие правила dialog на сайте дают поля 90/50px — у этого окна свои. */
  width: min(760px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  margin: auto;
  border: 0;
  border-radius: 14px;
  padding: 0;
  background: var(--surface, #fff);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.28);
}

.print-dialog::backdrop {
  background: rgba(16, 24, 40, 0.55);
}

.print-dialog__box {
  display: grid;
  gap: 14px;
  padding: 22px 24px;
}

.print-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.print-dialog__head h2 {
  margin: 0;
  font-size: 1.35rem;
}

.print-dialog__box > .muted {
  margin: 0;
}

.print-dialog__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  font-size: 0.9rem;
}

.print-dialog__tools [data-print-count] {
  margin-right: auto;
  font-weight: 700;
}

.print-dialog__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  /* Без этого строки сетки ужимаются под max-height и фото сплющиваются. */
  grid-auto-rows: max-content;
  gap: 10px;
  max-height: min(46dvh, 420px);
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
}

.print-photo {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #ddd;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 0;
}

.print-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.45;
  transition: opacity 120ms ease-out;
}

.print-photo input {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--brass-dark, #96762a);
}

.print-photo:has(input:checked) {
  outline-color: var(--brass, #d4af37);
}

.print-photo:has(input:checked) img {
  opacity: 1;
}

.print-photo:has(input:focus-visible) {
  outline-color: var(--ink);
}

.print-dialog__full {
  margin: 0;
  font-weight: 600;
}

.print-dialog__comments {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.print-dialog__comments textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  font: inherit;
  font-weight: 400;
}

.print-dialog__status {
  min-height: 1.2em;
  margin: 0;
  color: var(--brass-dark, #96762a);
  font-size: 0.9rem;
}

.print-dialog__status:empty {
  display: none;
}

.print-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.print-dialog__actions .btn[disabled] {
  opacity: 0.55;
  cursor: progress;
}

@media (max-width: 680px) {
  /* Как .property-head-actions: на телефоне блок цены выровнен влево. */
  .property-doc-actions {
    justify-content: flex-start;
  }

  .print-dialog__box {
    padding: 18px 16px;
  }

  .print-dialog__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .print-dialog__actions .btn {
    flex: 1 1 auto;
  }
}

html[data-theme="night"] .print-dialog {
  background: var(--surface);
  color: var(--ink);
}

html[data-theme="night"] .print-dialog::backdrop {
  background: rgba(6, 10, 16, 0.72);
}

/* Печатный лист: на экране его нет, в печать идёт только он (класс is-printing ставит скрипт).
   Обычная печать страницы через Ctrl+P остаётся как была. */
.print-sheet {
  display: none;
}

@media print {
  @page {
    size: A4;
    margin: 14mm 14mm 16mm;
  }

  body.is-printing {
    background: #fff !important;
  }

  body.is-printing > :not(.print-sheet) {
    display: none !important;
  }

  body.is-printing .print-sheet {
    display: block;
    color: #101828;
    font-family: "Manrope", Arial, sans-serif;
    font-size: 10pt;
    line-height: 1.45;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Ночная тема перекрашивает заголовки и приглушает фото — на бумаге это не нужно. */
  body.is-printing .print-sheet h1,
  body.is-printing .print-sheet h2,
  body.is-printing .print-sheet__desc p,
  body.is-printing .print-sheet__comments p,
  body.is-printing .print-spec strong {
    color: #101828;
  }

  body.is-printing .print-sheet__head span,
  body.is-printing .print-sheet__ref,
  body.is-printing .print-sheet__loc,
  body.is-printing .print-spec span,
  body.is-printing .print-sheet__foot {
    color: #6a7282;
  }

  body.is-printing .print-sheet__head strong,
  body.is-printing .print-sheet__price,
  body.is-printing .print-sheet__eyebrow {
    color: #96762a;
  }

  body.is-printing .print-sheet img {
    filter: none !important;
    opacity: 1 !important;
  }

  .print-sheet__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 6px;
    border-bottom: 1.5px solid #96762a;
  }

  .print-sheet__head strong {
    color: #96762a;
    font-size: 17pt;
    letter-spacing: 0.04em;
  }

  .print-sheet__head span {
    color: #6a7282;
    font-size: 8pt;
    word-break: break-all;
  }

  .print-sheet__ref {
    margin: 8px 0 2px;
    color: #6a7282;
    font-size: 8.5pt;
  }

  .print-sheet h1 {
    margin: 0 0 2px;
    font-size: 18pt;
    line-height: 1.2;
  }

  .print-sheet__loc {
    margin: 0;
    color: #6a7282;
  }

  .print-sheet__price {
    margin: 4px 0 10px;
    color: #96762a;
    font-size: 13pt;
    font-weight: 700;
  }

  .print-sheet__photos {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3mm;
  }

  .print-sheet__photos:empty {
    display: none;
  }

  .print-sheet__photos img {
    display: block;
    width: 100%;
    height: 58mm;
    object-fit: cover;
    break-inside: avoid;
  }

  .print-sheet__photos img:first-child {
    grid-column: 1 / -1;
    height: 100mm;
  }

  .print-sheet section {
    margin-top: 7mm;
  }

  .print-sheet.is-short [data-print-full],
  .print-sheet.is-no-desc [data-print-desc],
  .print-sheet [data-print-comments][hidden] {
    display: none;
  }

  .print-sheet .print-sheet__comments {
    margin: 0 0 5mm;
  }

  .print-sheet__comments p {
    margin: 0;
    white-space: pre-line;
  }

  .print-sheet__eyebrow {
    margin: 0 0 1mm;
    color: #96762a;
    font-size: 7.5pt;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .print-sheet h2 {
    margin: 0 0 2mm;
    font-size: 13pt;
    break-after: avoid;
  }

  .print-specs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 6mm;
  }

  .print-spec {
    display: flex;
    justify-content: space-between;
    gap: 4mm;
    padding: 1.2mm 0;
    border-bottom: 0.5pt solid #d1d5dc;
    break-inside: avoid;
  }

  .print-spec span {
    color: #6a7282;
  }

  .print-spec strong {
    text-align: right;
  }

  .print-sheet__desc p {
    margin: 0 0 2.5mm;
    orphans: 3;
    widows: 3;
  }

  .print-sheet__foot {
    margin-top: 8mm;
    padding-top: 2mm;
    border-top: 0.5pt solid #d1d5dc;
    color: #6a7282;
    font-size: 7.5pt;
  }
}
