:root{
  --accent:#2d7bf4;
  --muted:#6b7280;
  --err:#d23b3b;
  --paper-bg:#ffffff;
}

/* Контейнер конструктора */
.cb-wrapper{
  max-width:980px;
  margin:18px auto;
  font-family:Arial,Helvetica,sans-serif;
  background:#fbfdff;
  padding:16px;
  border-radius:10px;
  border:1px solid #eef2f7;
  box-shadow:0 6px 24px rgba(10,20,50,0.04);
  position:relative;
  z-index:5;
}

/* Сетка */
.cb-row{display:flex;gap:12px;flex-wrap:wrap}
.cb-col{flex:1 1 300px;min-width:260px}

/* Поля формы */
label{display:block;font-weight:700;margin:10px 0 6px;font-size:13px}
input[type=text],input[type=date],textarea,select{
  width:100%;padding:9px 10px;border:1px solid #d6dbe6;
  border-radius:8px;box-sizing:border-box;font-size:14px;background:#fff
}
textarea{min-height:88px;resize:vertical}
.hint{font-size:13px;color:var(--muted);background:#f6fbff;padding:8px;border-left:3px solid var(--accent);border-radius:6px}

/* Кнопки */
.controls{margin-top:12px;display:flex;gap:8px;flex-wrap:wrap}
.btn{padding:10px 14px;border-radius:8px;border:0;cursor:pointer;font-weight:700;font-size:14px}
.btn-primary{background:var(--accent);color:#fff}
.btn-ghost{background:#fff;border:1px solid #e6e9f2;color:#0b1220}

/* Предпросмотр A4 */
.preview-wrap{margin-top:16px}
.doc-preview{
  width:210mm;
  min-height: auto;
  margin:12px auto;
  background:var(--paper-bg);
  box-shadow:0 6px 18px rgba(15,23,42,0.06);
  box-sizing:border-box;color:#111;
  font-family:"Times New Roman",Times,serif;
  font-size:12pt;line-height:1.5;
  position:relative;
  padding:20mm 15mm 20mm 15mm;
  overflow:visible;
}

/* Основные стили текста */
.doc-preview p{
  text-indent:0.8cm;
  text-align:justify;
  text-justify:inter-word;
  margin:0 0 4pt 0;
  line-height:1.4;
}

/* Шапка */
.a4-header{width:100%;display:block;margin-bottom:10mm;position:relative;overflow:visible;}
.header-right{float:right;width:9.5cm;text-align:right;box-sizing:border-box;}
#docBody{clear:both !important;}
.title{text-align:center;font-weight:700;font-size:16pt;margin:0 auto 10mm auto;width:100%;clear:both;}

/* Подпись - увеличенный отступ на одну строку */
.sig-row{
  display:flex;
  justify-content:space-between;
  margin-top: 1.5em; /* Увеличил отступ до 1.5 строки */
  align-items:center;
  page-break-inside: avoid;
  break-inside: avoid;
}

.inline-sign{display:flex;gap:20px;align-items:center}
.inline-sign .label{font-weight:600;margin-right:6px}

/* Валидация */
.field-error{border-color:var(--err)!important;box-shadow:0 0 0 3px rgba(210,59,59,0.06)}
.error-box{background:#fff5f5;border:1px solid rgba(210,59,59,0.2);color:var(--err);padding:10px 12px;border-radius:8px;margin-bottom:12px;display:none}
.error-box ul{margin:6px 0 0 18px}
.preview-header{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-top:8px}
.preview-header .muted{margin:0}

/* Адаптив */
@media (max-width:900px){
  .cb-row{flex-direction:column}
  .doc-preview{padding:12mm;width:100%}
  .header-right{float:none;width:auto;text-align:left}
  .title{margin-bottom:8mm}
}

/* ----------- PRINT (улучшенная версия) ------------- */
@media print {
  /* Полностью убираем все тени, эффекты и границы */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
    filter: none !important;
    -webkit-filter: none !important;
  }
  
  /* Убираем границу у основного контейнера */
  .cb-wrapper {
    border: none !important;
  }

  /* Скрываем только ненужные элементы конструктора */
  .cb-wrapper > *:not(.preview-wrap),
  .preview-header,
  .muted{
    display:none !important;
  }

  /* Показываем только документ */
  .preview-wrap{
    display:block !important;
    margin:0 !important;
    padding:0 !important;
    width:100% !important;
    height:auto !important;
    position:static !important;
    border: none !important;
  }

  .doc-preview{
    width:210mm !important;
    min-height: auto !important;
    margin:0 auto !important;
    padding:20mm 15mm 20mm 15mm !important;
    box-shadow:none !important;
    background:#fff !important;
    border:none !important;
    outline:none !important;
    position:static !important;
    page-break-before:avoid !important;
    page-break-after:avoid !important;
  }

  /* Восстанавливаем правильное положение шапки */
  .a4-header{
    display:block !important;
    width:100% !important;
    margin-bottom:10mm !important;
  }
  
  .header-right{
    float:right !important;
    width:9.5cm !important;
    text-align:right !important;
    box-sizing:border-box !important;
  }

  /* Восстанавливаем стили для контента */
  .title{
    text-align:center !important;
    font-weight:700 !important;
    font-size:16pt !important;
    margin:0 auto 10mm auto !important;
    width:100% !important;
    clear:both !important;
  }

  #docBody{
    clear:both !important;
  }

  /* Оптимизируем отступы при печати */
  .doc-preview p{
    text-indent:0.8cm !important;
    margin:0 0 1pt 0 !important;
    line-height:1.25 !important;
  }

  /* Подпись при печати - увеличенный отступ */
  .sig-row{
    margin-top: 1.2em !important; /* Увеличил отступ при печати */
    page-break-inside:avoid !important;
    break-inside:avoid !important;
  }

  /* Настройки страницы */
  @page {
    size:A4;
    margin:20mm 15mm 20mm 15mm;
  }

  /* Убедимся, что все элементы документа видны */
  .doc-preview,
  .doc-preview * {
    visibility:visible !important;
  }

  /* Убираем лишние отступы и границы для печати */
  body, html {
    margin:0 !important;
    padding:0 !important;
    background:#fff !important;
    width:100% !important;
    height:auto !important;
    overflow:visible !important;
    border: none !important;
  }

  /* Гарантируем, что контейнер документа центрируется */
  body {
    display:block !important;
    position:static !important;
    border: none !important;
  }

  /* Дополнительно убираем любые возможные границы */
  .preview-wrap *,
  .doc-preview * {
    border: none !important;
    outline: none !important;
  }
}