
:root{
  --sig-right-offset-screen: 0mm;
  --sig-enter-gap: 6;
  --nr-prot: "";
}

html, body, .sheet, h1, h2, h3, p, table, th, td, input, label, button, select, textarea {
  font-family: Arial, sans-serif;
  font-size: 12px;
  line-height: 1.25;
  box-sizing: border-box;
}

body { margin: 0; padding: 20px; background: #2b2b2b; color: #fff; }
.sheet {
  background: #3a3a3a; color: #fff;
  width: 210mm; min-height: 297mm; margin: auto; padding: 20mm;
  border: 1px solid #666; box-shadow: 0 0 10px rgba(0,0,0,0.8);
  position: relative; display: flex; flex-direction: column;
}
@media screen { .sheet{ width: 240mm; } }

.toolbar {
  position: sticky; top: 0; background: #1f1f1f; padding: 8px; border-bottom: 1px solid #555;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; z-index: 10;
}
.toolbar .group { display: inline-flex; gap: 8px; align-items: center; }
.toolbar .spacer { flex: 1; }
.btn, .toolbar button, .toolbar select, .toolbar a.btn {
  font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px;
  background: #333; color: #eee; border: 1px solid #555; border-radius: 6px; cursor: pointer; text-decoration: none;
}
.btn.secondary { background: #2a2a2a; }
.btn.small{ padding:4px 8px; font-size:11px; }
.btn:hover, .toolbar button:hover, .toolbar a.btn:hover { background: #3a3a3a; }
.hidden { display: none; }

h1 { text-align: center; margin: 5px 0; font-size: 0; }
.h1-label { display: inline-block; font-size: 18px; }
h1 input { font-size: 18px; background: transparent; color: inherit; border: 0; outline: 0; margin-left: 10px; }

h2 { text-align: center; margin: 2px 0 0; font-weight: normal; }
.h2-sub { text-align:center; margin: 0 0 6px; opacity: .95; }

.meta-inline { display:flex; align-items:center; gap:6px; justify-content:center; margin: 8px 0 12px; }
.field-mini { display:inline-flex; align-items:center; gap:6px; background:#3e3e3e; border:1px solid #666; border-radius:4px; padding:2px 4px; }
.field-mini input {
  background:#555; color:#fff; border:1px solid #777; height:22px; padding:0 6px; text-align:center;
  min-width:12ch; max-width:100%;
}

.sec-title{ font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:#fff; display:inline; }
.meta-grid{ margin-bottom: 12mm; }

.meta-inlinepairs { display: flex; flex-direction: column; gap: 6px; }
.meta-inlinepairs .pair { display: flex; align-items: flex-start; gap: 6px; }
.meta-inlinepairs label {
  white-space: nowrap; margin: 0;
  font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:#fff; min-width:max-content;
  line-height: 22px;
}
.meta-inlinepairs .pair input.meta-inline-input {
  flex: 0 0 auto; width: auto; min-width: 10ch; max-width: 100%;
  font-size: 12px; padding: 4px 6px;
  background: #555; color: #fff; border: 1px solid #777; height: 22px; line-height: 22px;
  text-align: left; vertical-align: baseline;
}

.pair.orz-pair{ align-items: baseline; }
.pair.orz-pair label{ line-height: 1.25; }
.orz-out{ flex:1; display:inline-flex; align-items:baseline; }
.orz-text{ margin:0; white-space: normal; display:inline; }

.text-box, .cell-text, .title-ta {
  width: 100%; background:#555; color:#fff; border:1px solid #777;
  padding: 6px 8px; border-radius: 4px; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; resize: none; overflow: hidden; transition: height .15s ease;
}
td:nth-child(2) .cell-text { background:#555; }

.title-ta{ text-align:center; font-weight:bold; border:0; background:transparent; padding:2px 0; }

.table-box{ position: relative; padding-right: 28px; }
.row-delete-layer{
  position: absolute; top: 0; right: 0; width: 24px; height: 100%;
  pointer-events: none;
}
.row-delete-layer .del-btn{
  position: absolute; right: 0;
  width: 18px; height: 18px;
  border: 1px solid #8e1b1b;
  background: #c62828;
  color:#fff;
  border-radius: 4px; cursor: pointer; line-height: 16px;
  display: flex; align-items:center; justify-content:center;
  padding: 0; font-weight: 700; pointer-events: auto; user-select: none;
  opacity:.98;
}
.row-delete-layer .del-btn:hover{ background:#a71d1d; border-color:#7a1313; }
.row-delete-layer .del-btn:focus-visible{ outline:2px solid #fff; outline-offset:1px; }
body.light .row-delete-layer .del-btn{ background:#c62828; border-color:#8e1b1b; color:#fff; }

.toast{
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: rgba(40,40,40,.95); color:#fff; border:1px solid #666; border-radius:8px;
  padding:8px 12px; z-index:10000; font-size:12px; box-shadow:0 6px 18px rgba(0,0,0,.35);
}
body.light .toast{ background:#111; color:#fff; border-color:#000; }

#tabela { width: 100%; border-collapse: collapse; margin: 10px 0 15px; background: #444; color: #fff; table-layout: fixed; }
#tabela, #tabela * { font-size: 11px; }
table, th, td { border: 1px solid #888; padding: 4px 6px; text-align: center; vertical-align: middle; }
th { background: #555; font-weight: bold; }
#tabela th, #tabela td { word-break: break-word; }
#tabela td:nth-child(2) { text-align: left; vertical-align: middle; white-space: normal; }

#tabela col:nth-child(1){ width:6% }
#tabela col:nth-child(2){ width:34% }
#tabela col:nth-child(3){ width:10% }
#tabela col:nth-child(4){ width:9% }
#tabela col:nth-child(5){ width:10% }
#tabela col:nth-child(6){ width:14% }
#tabela col:nth-child(7){ width:10% }
#tabela col:nth-child(8){ width:7% }

#tabela th:first-child, #tabela td.lp { text-align: center !important; vertical-align: middle !important; }
td.lp .lp-wrap{ display:flex; align-items:center; justify-content:center; gap:6px; }
.lp-num { display:inline-block; min-width:1.2em; text-align:center; }

.th-multi{ display:flex; flex-direction:column; align-items:center; line-height:1.1; }
.th-multi span{ display:block; }
#tabela th{ white-space:normal; }

.title-cell{ padding:0; }
.print-text{ display:none; }

td.ocena{ font-weight:700; }
td.ocena.tak{ background:#1f7a1f; color:#fff; }
td.ocena.nie{ background:#8b1a1a; color:#fff; }

.after-table{ margin-top: 12mm; }
.table-note{ font-size: 8px; line-height: 1.2; opacity: .9; margin-top: 2px; }

body.light { background:#f7f7f7; color:#111; }
body.light .sheet { background:#fff; color:#000; border-color:#ccc; box-shadow: none; }
body.light .toolbar { background:#f0f0f0; border-bottom-color:#ddd; }
body.light .btn, .toolbar button, .toolbar select, .toolbar a.btn { background:#fff; color:#111; border-color:#ccc; }
body.light .meta-inlinepairs label, body.light .sec-title, body.light .sig-label, body.light h1 .h1-label { color:#000; }
body.light .meta-inlinepairs .pair input.meta-inline-input,
body.light .field-mini input[type="text"],
body.light .field-mini input[type="date"] { background:#fff; color:#000; border-color:#ccc; }
body.light .field-mini { background:#fff; border-color:#ccc; }
body.light .cell-text { background:#eee; color:#000; border-color:#ccc; }
body.light .text-box, .title-ta { background:#fff; color:#000; border-color:#ccc; }
body.light #tabela { background:#fff; color:#000; }
body.light th { background:#f7f7f7; }

.signatures{
  width:100%;
  margin-top: calc(var(--sig-enter-gap) * 1.25em);
  display:grid;
  grid-template-columns: 1fr auto 1fr;
  column-gap: 12mm;
  align-items:end;
  box-sizing: border-box;
  padding-right: var(--sig-right-offset-screen);
}
.signatures .left{ display:flex; flex-direction:column; gap:6px; min-width:60mm; max-width:100%; grid-column:1; }
#sig_wykonal_box{ grid-column:2; justify-self:center; }
#sig_sprawdzil_box{ grid-column:3; justify-self:end; }

.sig-box{ text-align:center; width:100%; }
.sig-space{ display:block; font-size: 12px; letter-spacing: .8px; margin-bottom: 3mm; }
.sig-space .dots{ user-select:none; }
.sig-label{ font-weight: normal; text-transform: none; letter-spacing: 0; line-height: 1.2; }

.quick-panel{
  position: fixed;
  z-index: 9999;
  left: 16px;
  bottom: 16px;
  width: min(560px, 95vw);
  max-height: 85vh;
  overflow: auto;
  background:#2f2f2f;
  border:1px solid #555;
  border-radius:8px;
  padding:10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  margin: 0;
}
body.light .quick-panel{ background:#fafafa; border-color:#ddd; }
.quick-head{ display:flex; gap:12px; align-items:center; flex-wrap:wrap; margin-bottom:8px; cursor: move; }
.quick-head .lp-badge{ font-weight:700; padding:2px 8px; border-radius:12px; border:1px solid #777; background:#3a3a3a; }
body.light .quick-head .lp-badge{ background:#fff; border-color:#bbb; }
.chips{ display:flex; gap:6px; flex-wrap:wrap; }
.chip{ padding:4px 8px; border:1px solid #777; border-radius:999px; background:#3a3a3a; cursor:pointer; user-select:none; }
.chip:hover{ background:#444; }
body.light .chip{ background:#fff; border-color:#bbb; }
.grid{ display:grid; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); gap:6px; margin-top:8px; }
.grid .gbtn{ padding:6px 0; border:1px solid #777; border-radius:8px; background:#3a3a3a; cursor:pointer; text-align:center; }
.gbtn:hover{ background:#444; }
body.light .gbtn{ background:#fff; border-color:#bbb; }
.type-tabs{ display:flex; gap:6px; flex-wrap:wrap; margin-top:6px; }
.type-tabs .tab{ padding:4px 10px; border:1px solid #777; border-radius:8px; background:#3a3a3a; cursor:pointer; }
.type-tabs .tab.active{ outline:2px solid #999; }
body.light .type-tabs .tab{ background:#fff; border-color:#bbb; }

.hide-signature-footer{ display:none !important; }

/* ====== UWAGI – contenteditable + horyzontalny autogrow ====== */
.pair--uwagi{ align-items: baseline; }
.uwagi-wrap{
  position: relative;
  display: inline-flex;
  align-items: baseline;
  flex: 1 1 auto;
  min-width: 0;
}
#uwagi{
  display: inline-block;
  min-width: 6ch;
  max-width: 100%;
  background: transparent;
  color: inherit;
  border: 0;
  border-radius: 0;
  padding: 0 8px;
  box-sizing: border-box;
  outline: none;
  line-height: 1.25;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  vertical-align: baseline;
}
#uwagi::first-line{ line-height: 22px; }
#uwagi:empty::before{ content: attr(data-placeholder); opacity:.7; font-style: normal; }
@media screen {
  #uwagi:empty::before{ color:#fff; }
  body.light #uwagi:empty::before{ color:#000; }
}

@page {
  size:A4;
  margin: 10mm 10mm 30mm 10mm;
  @bottom-center {
    content: var(--nr-prot) "Strona " counter(page) " / " counter(pages);
    font-size: 10px;
  }
}

@media print{
  body, .sheet, .meta-inlinepairs label, .sec-title, .sig-label, h1 .h1-label, h2, .h2-sub, * {
    color:#000 !important;
  }
  body { background:#fff !important; }
  .sheet{ display:block !important; padding:0 !important; background:#fff !important; border:none !important; box-shadow:none !important; width:auto !important; min-height:auto !important; }

  #addRowBtn, #addTitleBottomBtn, #insertAtLpBtn, #toggleQuickBtn, #quickPanel, #importJsonBtn { display:none !important; }

  thead { display: table-header-group !important; }
  tfoot { display: table-row-group !important; }
  #tabela tr, #tabela td, #tabela th { break-inside: avoid !important; page-break-inside: avoid !important; }

  #tabela { table-layout: fixed !important; width:100% !important; border-collapse:collapse!important; }
  #tabela th, #tabela td { border:1px solid #000!important; padding: 1px 3px !important; }
  #tabela{ margin-bottom: 6mm !important; }

  .toolbar{ display:none !important; }

  td:nth-child(2) textarea.cell-text{ display:none !important; }
  td:nth-child(2) .cell-print{
    display:block !important;
    white-space: pre-wrap !important;
    word-break: break-word !important;
    height: auto !important;
    overflow: visible !important;
    font-weight: normal !important;
  }

  .title-ta{ display:none !important; }
  td.title-cell .print-text{
    display:block !important; white-space:pre-wrap; word-break:break-word; width:100% !important; margin:0 !important;
    text-align:center !important; font-weight:bold !important;
  }

  .row-delete-layer{ display:none !important; }

  #afterTable{
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  #afterTable .signatures{
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  input, select, textarea { border:0 !important; background:transparent !important; padding:0 !important; height:auto !important; box-shadow:none !important; }
  .field-mini{ border:0 !important; background:transparent !important; }

  .page-title{ page-break-after: avoid; }
  .section{ page-break-inside: avoid; }

  #pageNumbers{ display:none !important; }
  i[class^="fa"], i[class*=" fa"]{ display:none !important; }

  #uwagi{
    border: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    width: 100% !important;
    white-space: pre-wrap !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    line-height: 1.25 !important;
  }
  #uwagi::first-line{ line-height: 22px !important; }
  #uwagi:empty::before{ color:#000 !important; opacity:1 !important; }
}

#pageNumbers{ display:none; }

/* WATERMARK (widok + druk) */
.watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-30deg);
  font-size: 90px;
  font-weight: 900;
  color: rgba(200, 0, 0, 0.15);
  z-index: 9999;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}
@media print {
  .watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 120px;
    font-weight: 900;
    color: rgba(150, 0, 0, 0.2);
    z-index: 9999;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
