/* ============================================================
   СПРАВОЧНИК ТОВАРОВ GEM — печатный/экранный стиль
   Основано на фирменном стиле main.css (mkgem.ru)
   Шрифты: TikTok Sans (заголовки), Onest (основной)
   Цвета:  #041b2d тёмный, #0778c1 акцент, #e6ecf2 линии
   ============================================================ */

:root {
  --ref-ink: #041b2d;          /* основной тёмный */
  --ref-accent: #0778c1;       /* акцент синий */
  --ref-line: #e6ecf2;         /* границы/линии */
  --ref-line-soft: #f1f5f9;    /* разделители строк */
  --ref-bg-head: #eef3f7;      /* подложка заголовка таблицы */
  --ref-muted: #76848f;        /* приглушённый текст */
  --ref-shadow: 0 4px 12px rgba(4, 27, 45, .04);
  --ref-font: "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ref-font-head: "TikTok Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* ---------- Экранный предпросмотр (лист A4) ---------- */
.ref-body {
  margin: 0;
  padding: 24px;
  background: #f3f7f9;
  color: var(--ref-ink);
  font-family: var(--ref-font);
  font-size: 12px;
  line-height: 1.4;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ref-page {
  max-width: 210mm;
  margin: 0 auto;
  background: hsl(0deg 0% 100% / 61%);
  padding: 12mm;
  position: relative;
}

/* Фон-водяной знак на ОСНОВНОЙ части страницы (весь фон браузера) — 30% */
.ref-body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url('/assets/img/fonspravochnik.png') no-repeat center;
  background-size: cover;
  opacity: 0.3;
  z-index: 0;
  pointer-events: none;
}

/* ---------- КОНТЕЙНЕР СТРАНИЦ Paged.js: центрирование через flex ---------- */
.pagedjs_pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* Водяной знак на КАЖДОМ листе Paged.js (30%) */
.pagedjs_pagebox {
  position: relative;
  border: 1px solid gray;
  border-radius: 5px;
  margin-bottom: 14px;   /* отступ снизу между листами */
  background: #fff;
  box-shadow: var(--ref-shadow);
}
.pagedjs_pagebox:last-child { margin-bottom: 0; }
.pagedjs_pagebox::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url('/assets/img/fonspravochnik.png') no-repeat center;
  background-size: cover;
  opacity: 0.3;
  z-index: 0;
  pointer-events: none;
  border-radius: 5px;
}
.pagedjs_pagebox > .pagedjs_page { position: relative; z-index: 1; }

/* ---------- Шапка справочника ---------- */
.ref-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--ref-ink);
  padding-bottom: 8px;
  margin-bottom: 16px;
  gap: 16px;
}
.ref-header__left { display: flex; align-items: center; gap: 12px; }
.ref-header__logo img { height: 34px; display: block; }
.ref-header__brand { font-weight: 700; font-size: 18px; }
.ref-header__sub { font-size: 11px; color: var(--ref-muted); }
.ref-header__right { text-align: right; font-size: 11px; line-height: 1.6; padding-bottom: 6px; }
.ref-header__strong { font-weight: 700; }
/* черта под датой + отступ */
.ref-header__right::after {
  content: "";
  display: block;
  width: 100%;
  height: 2px;
  background: #0778c1;
  margin-top: 6px;
}

/* ---------- Заголовок категории ---------- */
.ref-cat {
  font-family: var(--ref-font-head);
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ref-ink);
  border-bottom: 1px solid var(--ref-ink);
  padding-bottom: 5px;
  margin: 0 0 14px;
}

/* ---------- Блок товара ---------- */
.ref-product {
  margin-bottom: 16px;
}

/* Название товара */
.ref-product__title {
  display: block;
  font-family: var(--ref-font-head);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ref-ink);
  border-bottom: 1px solid var(--ref-ink);
  padding: .3rem 1rem;
  margin-bottom: 10px;
}

/* Подкатегория (раздел товара) — градиентный бейдж */
.ref-product__category {
  display: block;
  width: 100%;
  background: linear-gradient(90deg, #0778c1 0%, #fff 66%);
  border-radius: 20px;
  padding: .4rem 1.2rem;
  font-family: var(--ref-font-head);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-align: left;
  letter-spacing: .3px;
  margin-bottom: 10px;
}

/* Ряд картинок: чертёж | фото (равные доли) */
.ref-product__media-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.ref-product__media {
  min-width: 0;
  flex: 1 1 0;               /* равные доли 50/50 */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Чертёж: минимум 200px, без рамки */
.ref-product__media--drawing img {
  display: block;
  width: 100%;
  height: auto;
  min-height: 200px;
  object-fit: contain;
}

/* Фото: рамка на самом img */
.ref-product__media--photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 2px solid #0778c1;
  box-shadow: 0 2px 6px rgba(4, 27, 45, .06);
}

.ref-product__drawing-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 12px;
  border: 2px dashed #a8b2ba;
  border-radius: 10px;
  color: var(--ref-muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- Краткое описание товара ---------- */
.ref-product__desc {
  margin: 1rem;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--ref-ink);
  background: #f3f7f9;
  border: 1px solid var(--ref-line);
  border-radius: 8px;
}

/* ---------- Подзаголовок группы (если у товара несколько таблиц) ---------- */
.ref-group-title {
  font-family: var(--ref-font-head);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--ref-accent);
  border-left: 3px solid var(--ref-accent);
  padding: 2px 8px;
  margin: 12px 0 4px;
}

/* ---------- Таблица модификаций ---------- */
.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
.ref-table th,
.ref-table td {
  border: 1px solid var(--ref-line);
  padding: 5px 7px;
  text-align: center;
  color: var(--ref-ink);
}
.ref-table thead th {
  background: #0778c1;
  color: #fff;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 9.5px;
  letter-spacing: .4px;
}
.ref-table tbody tr:nth-child(even) { background: #fafbfd; }
.ref-table tbody tr:hover { background: #f3f7f9; }

/* ---------- Таблицы внутри товара (из TV: class="tovar-table") ---------- */
.ref-product table,
.ref-product .tovar-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
.ref-product table th,
.ref-product table td {
  border: 1px solid var(--ref-line);
  padding: 5px 7px;
  text-align: center;
  color: var(--ref-ink);
}
.ref-product table thead th {
  background: #0778c1;
  color: #fff;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 9.5px;
  letter-spacing: .4px;
}
.ref-product table tbody tr:nth-child(even) { background: #fafbfd; }
.ref-product table tbody tr:hover { background: #f3f7f9; }

/* ---------- Оглавление ---------- */
.ref-toc {
  border: 1px solid var(--ref-line);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 0 0 20px;
  background: #fff;
}
.ref-toc__title {
  font-family: var(--ref-font-head);
  font-size: 15px;
  font-weight: 700;
  color: var(--ref-ink);
  margin: 0 0 10px;
}
.ref-toc__item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 11px;
  padding: 4px 0;
  border-bottom: 1px dotted var(--ref-line);
}
.ref-toc__item:last-child { border-bottom: none; }
.ref-toc__item a {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--ref-ink);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 700;
}
/* Номер страницы товара — подставляет Paged.js через target-counter */
.ref-toc__item a::after {
  content: target-counter(attr(href), page);
  white-space: nowrap;
  color: var(--ref-accent);
  font-weight: 700;
  font-size: 1.1rem;
}

/* ---------- Кнопка печати (только экран) — фикс. сверху справа ---------- */
.ref-print-btn {
  position: fixed !important;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border: none;
  border-radius: 8px;
  background: var(--ref-accent);
  color: #fff;
  font-family: var(--ref-font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--ref-shadow);
  transition: opacity .2s ease;
}
.ref-print-btn:hover { opacity: .88; }

/* Кнопка «Наверх» — фикс. сверху слева */
.ref-top-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 9999;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10%;
  border: none;
  background: var(--ref-accent);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--ref-shadow);
  opacity: .9;
  transition: opacity .2s ease, transform .2s ease;
  position: fixed;
  bottom: 0;
}
.ref-top-btn:hover { opacity: 1; transform: translateY(-3px); }

/* ============================================================
   ПЕЧАТЬ (A4)
   ============================================================ */
@page {
  size: A4 portrait;
  margin: 10mm 10mm 22mm 10mm;   /* снизу больше — чтобы номер страницы был виден при печати */
  @bottom-right { content: counter(page); }
  @bottom-left  { content: "Справочник GEM"; }
}
@media print {
  .ref-body { padding: 0; background: #fff; }
  .ref-page {
    max-width: 100%;
    margin: 0;
    padding: 0;   /* поля теперь из @page margin, а не из паддинга */
    box-shadow: none;
    border-radius: 0;
    position: relative;
  }

  /* Фон-картинка на КАЖДУЮ страницу (fixed повторяется при печати) — 30% opacity */
  .ref-body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('/assets/img/fonspravochnik.png') no-repeat center top;
    background-size: 100% 100%;
    opacity: 0.3;
    z-index: -1;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  /* Контент поверх фона */
  .ref-page { position: relative; z-index: 0;padding: .3rem !important;
    border-radius: 6px; }

  /* Не разрывать картинки/название с началом контента, но длинную таблицу
     разрешаем переносить по строкам (иначе рвётся по середине строки) */
  .ref-product {
    display: block;
    position: relative;
  }
  /* Шапка товара (название + бейдж + картинки) — неделима: переносится целиком */
  .ref-product__head {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .ref-product__media-row {
    break-after: avoid;
    page-break-after: avoid;
  }
  .ref-product__title {
    break-after: avoid;
    page-break-after: avoid;
  }
  .ref-product__category {
    break-after: avoid;
    page-break-after: avoid;
  }
  .ref-group-title {
    break-after: avoid;
    page-break-after: avoid;
  }
  .ref-product table, .ref-table { orphans: 2; widows: 2; }
  /* Строки не разрывать и повторять шапку на каждой странице */
  .ref-product table tbody tr, .ref-table tbody tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .ref-product table thead, .ref-table thead {
    display: table-header-group;
  }
  .ref-product table tr, .ref-product table th, .ref-product table td,
  .ref-table tr, .ref-table th, .ref-table td {
    break-inside: avoid;
  }
}

/* ---------- Титульный лист (страница-обложка) ---------- */
.ref-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 220mm;
  padding: 10mm 0;
  page-break-after: always;
  break-after: page;
}

.ref-cover__visual {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.ref-cover__img {
  display: block;
  width: 165mm;
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  box-shadow: var(--ref-shadow);
}

.ref-cover__logo {
  position: absolute;
  left: 50%;
  bottom: -157px;
  transform: translateX(-50%);
  width: 320px;
  height: 320px;
  padding: 10px;
  background: #ffffffa6;
  border-radius: 50%;
  box-shadow: var(--ref-shadow);
  object-fit: contain;
}

.ref-cover__logo--plain {
  position: static;
  transform: none;
  border-radius: 0;
  box-shadow: none;
  width: 160px;
  height: 160px;
  margin-bottom: 12px;
}

.ref-cover__caption {
  margin-top: 64px;
  margin-bottom: 260px;
  z-index: 999;
}

.ref-cover__label {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ref-accent);
}

.ref-cover__title {
  margin: 6px 0 0;
  font-family: var(--ref-font-head);
  font-size: 53px;
  font-weight: 800;
  line-height: 1.15;
  color: var(--ref-ink);
}

/* ---------- Контакты отделов (фикс. страница в конце) ---------- */
.ref-contacts {
  page-break-before: always;
  break-before: page;
  padding-top: 8mm;
}

.ref-contacts__title {
  margin: 0 0 6mm;
  font-family: var(--ref-font-head);
  font-size: 26px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ref-ink);
  text-align: center;
  padding-bottom: 4mm;
  border-bottom: 3px solid var(--ref-accent);
}

.ref-contacts__section {
  margin-bottom: 4.5mm;
  page-break-inside: avoid;
  break-inside: avoid;
}

.ref-contacts__section-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 16px;
  background: var(--ref-bg-head);
  border-left: 4px solid var(--ref-accent);
  padding: 2mm 4mm;
  border-radius: 4px;
  margin-bottom: 3mm;
}

.ref-contacts__section-name {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--ref-ink);
}

.ref-contacts__section-phone {
  font-weight: 600;
  font-size: 11px;
  color: var(--ref-accent);
  white-space: nowrap;
}

.ref-contacts__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3mm;
}

.ref-contacts__person {
  border: 1px solid var(--ref-line);
  border-radius: 6px;
  padding: 2.5mm 4mm;
}

.ref-contacts__person-name {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ref-ink);
}

.ref-contacts__person-role {
  margin-top: 1mm;
  font-size: 10.5px;
  color: var(--ref-muted);
  line-height: 1.3;
}

.ref-contacts__footer {
  margin-top: 6mm;
  border-top: 2px solid var(--ref-accent);
  padding-top: 4mm;
  page-break-inside: avoid;
  break-inside: avoid;
}

.ref-contacts__footer-title {
  font-family: var(--ref-font-head);
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--ref-accent);
  margin-bottom: 2mm;
}

.ref-contacts__footer-row {
  font-size: 11.5px;
  color: var(--ref-ink);
  line-height: 1.7;
}

.ref-contacts__footer-row b {
  font-weight: 700;
}
