/* ===== COMMON UI (scoped by .gost-test) ===== */
.gost-test, .gost-test *{box-sizing:border-box;font-family:'Segoe UI',Tahoma,Geneva,Verdana,sans-serif;}
.gost-test{color:#333; line-height:1.45; margin:18px 0;}
.gost-test .container{max-width:1180px;margin:0 auto;background:#fff;padding:24px;border-radius:12px;box-shadow:0 0 20px rgba(0,0,0,.08);}
.gost-test h1,.gost-test h2,.gost-test h3{color:#2c3e50;margin:0 0 12px;}
.gost-test h1{border-bottom:2px solid #3498db;padding-bottom:10px;margin-bottom:18px;font-size:22px;}
.gost-test .muted{color:#6c757d;font-size:13px;}
.gost-test .section{margin:14px 0;padding:0;border:none;border-radius:0;background:#fff;}
.gost-test .grid{display:grid;grid-template-columns:repeat(12,1fr);gap:10px;}
.gost-test .col-12{grid-column:span 12;}
.gost-test .col-6{grid-column:span 6;}
.gost-test .col-4{grid-column:span 4;}
.gost-test .col-3{grid-column:span 3;}
.gost-test .col-2{grid-column:span 2;}
.gost-test label{display:block;margin-bottom:4px;font-weight:700;color:#2c3e50;font-size:13px;}
.gost-test input,.gost-test select,.gost-test textarea{
  width:100%; padding:8px 10px; border:1px solid #cfd6dd; border-radius:8px;
  font-size:14px; background:#fff;
}
.gost-test textarea{min-height:38px; resize:vertical;}
.gost-test .btn-row{display:flex;flex-wrap:wrap;gap:10px;margin-top:10px;}
.gost-test button{
  background:#3498db;color:#fff;border:none;padding:9px 14px;border-radius:8px;
  cursor:pointer;font-size:14px;transition:background-color .2s;
}
.gost-test button:hover{background:#2980b9;}
.gost-test button.secondary{background:#95a5a6;}
.gost-test button.secondary:hover{background:#7f8c8d;}
.gost-test button.danger{background:#e74c3c;}
.gost-test button.danger:hover{background:#c0392b;}
.gost-test button.ghost{background:#eef3f7;color:#2c3e50;border:1px solid #d7e1ea;}
.gost-test button.ghost:hover{background:#e6eef5;}
.gost-test .table-wrap{width:100%;overflow-x:auto;border-radius:12px;}
.gost-test .table{
  width:100%; table-layout:fixed; border-collapse:separate; border-spacing:0; background:#fff;
  border:1px solid #e3e6ea; border-radius:10px; overflow:hidden; min-width:100%;
}
.gost-test .table th, .gost-test .table td{
  border-bottom:1px solid #eef1f4; border-right:1px solid #eef1f4;
  padding:8px; vertical-align:middle; font-size:13px;
}
.gost-test .table th:last-child, .gost-test .table td:last-child{border-right:none;}
.gost-test .table tr:last-child td{border-bottom:none;}
.gost-test .table thead th{background:#f1f7ff; color:#2c3e50; font-weight:900; text-align:center;}
.gost-test .calc{
  background:#f8fafc; color:#2c3e50; font-weight:800; border-radius:8px;
  padding:8px 10px; border:1px dashed #d8e0e8; min-height:36px;
  display:flex; align-items:center; justify-content:center; text-align:center;
}
.gost-test .icon-btn{
  width:34px;height:34px;border-radius:10px;display:inline-flex;align-items:center;justify-content:center;
  background:#eef3f7;border:1px solid #d7e1ea;color:#2c3e50;font-weight:900;
}
.gost-test .icon-btn:hover{background:#e6eef5;}
.gost-test .icon-btn.danger{background:#fdecea;border-color:#f7c7c2;color:#a93226;}
.gost-test .icon-btn.danger:hover{background:#fbd9d6;}
.gost-test details{background:#fff;border:1px solid #e3e6ea;border-radius:12px;padding:10px 12px;}
.gost-test summary{cursor:pointer;font-weight:900;color:#2c3e50;font-size:15px;display:flex;align-items:center;justify-content:space-between;gap:10px;}
.gost-test summary::-webkit-details-marker{display:none;}
.gost-test .note{margin-top:10px; background:#e8f4fc; padding:10px; border-radius:10px; border-left:4px solid #3498db; font-weight:700; font-size:13px;}
.gost-test .legend-box{
  margin-top:16px;
  padding:18px 22px;
  background:#f4f8fc;
  border:1px solid #d6e3f3;
  border-radius:10px;
}
.gost-test .legend-box h3{margin:0 0 10px 0;font-size:16px;color:#2c3e50;}
.gost-test .legend-box ul{margin:0;padding-left:18px;}
.gost-test .legend-box li{margin-bottom:6px;font-size:14px;}

.gost-test input[type=number]::-webkit-outer-spin-button,
.gost-test input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0;}
.gost-test input[type=number]{-moz-appearance:textfield;}

@media (max-width:980px){
  .gost-test .col-6{grid-column:span 12;}
  .gost-test .col-4{grid-column:span 12;}
  .gost-test .col-3{grid-column:span 6;}
  .gost-test .col-2{grid-column:span 6;}
  .gost-test .table{min-width:980px;}
}
@media print{
  .gost-test .btn-row{display:none !important;}
  .gost-test .container{box-shadow:none;border:none;max-width:none;padding:0;}
}

/* === Fix header wrapping + shrink delete column === */
th{ white-space: nowrap; }
td:last-child, th:last-child{
  width: 56px !important;
  min-width: 56px !important;
  max-width: 56px !important;
  padding-left: 6px !important;
  padding-right: 6px !important;
  text-align: center !important;
}
td:last-child button{
  margin: 0 auto !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}
td:last-child .btn, td:last-child .btn-del, td:last-child .danger{
  margin: 0 auto !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}
/* Ensure 'Расхождение' column stays on one line and has enough width (Test 2: column before delete) */
table thead th:nth-last-child(2),
table tbody td:nth-last-child(2){
  white-space: nowrap;
  min-width: 110px;
}


/* ===== ONLY for Test 4.1 table ===== */
.pb41-wrap{overflow-x:auto}
.pb41-table{min-width:980px}
.pb41-table th,.pb41-table td{white-space:nowrap}
.pb41-table .pb41-del-h{width:52px;min-width:52px}
.pb41-table td.pb41-del{width:52px;min-width:52px}
.pb41-table th.pb41-avg-h{min-width:130px}
.pb41-table td.pb41-avg{min-width:130px}


/* === FIX 4.1 column widths === */
#test4_4_1 table input[type="number"]{
  width: 110px !important;
  min-width:110px !important;
}
#test4_4_1 table th,
#test4_4_1 table td{
  padding:6px 8px !important;
}


/* === 4.1 FIX WIDTH PROPERLY === */
#test4_4_1 table{
  table-layout: fixed;
  width: 100%;
}

#test4_4_1 th:nth-child(1),
#test4_4_1 td:nth-child(1){
  width: 50px;
}

#test4_4_1 th:nth-child(2),
#test4_4_1 th:nth-child(3),
#test4_4_1 th:nth-child(4),
#test4_4_1 th:nth-child(5),
#test4_4_1 th:nth-child(6),
#test4_4_1 td:nth-child(2),
#test4_4_1 td:nth-child(3),
#test4_4_1 td:nth-child(4),
#test4_4_1 td:nth-child(5),
#test4_4_1 td:nth-child(6){
  width: 95px;
}

#test4_4_1 th:nth-child(7),
#test4_4_1 td:nth-child(7){
  width: 130px;
}

#test4_4_1 th:nth-child(8),
#test4_4_1 td:nth-child(8){
  width: 110px;
}

#test4_4_1 input{
  width: 85px;
}


/* === 4.1 width fix (only test4) === */
#gost58406_test4 #tb41 input[type="number"]{
  width:100% !important;
  min-width:0 !important;
}
#gost58406_test4 .pb41-avg-h{white-space:nowrap;}


/* ===== CLEAN FIX: TEST 3 stays in one row (HTML + Bitrix safe) ===== */
#gost58406_test3 .grid{
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 20px !important;
}

#gost58406_test3 .col-4{
  grid-column: auto !important;
  width: auto !important;
  float: none !important;
  flex: unset !important;
}

#gost58406_test3 .col-12{
  grid-column: 1 / -1 !important;
  width: 100% !important;
  float: none !important;
}


/* ===== BITRIX OVERRIDE (high specificity) for TEST 3 ===== */
#gost58406_test3#gost58406_test3 .section .grid{
  display: grid !important;
  grid-template-columns: repeat(3, minmax(220px, 1fr)) !important;
  gap: 20px !important;
  width: 100% !important;
  justify-content: stretch !important;
  justify-items: stretch !important;
  align-items: start !important;
}
#gost58406_test3#gost58406_test3 .section .grid > .col-4{
  float: none !important;
  flex: none !important;
  width: auto !important;
  max-width: none !important;
}
#gost58406_test3#gost58406_test3 .section .grid > .col-12{
  grid-column: 1 / -1 !important;
  float: none !important;
  flex: none !important;
  width: auto !important;
  max-width: none !important;
}


/* ===== TEST 4.2 layout (scoped) ===== */
#gost58406_test4 .s42-toprow{
  display:flex;
  gap:16px;
  align-items:flex-end;
}
#gost58406_test4 .s42-total{flex:0 0 280px;}
#gost58406_test4 .s42-type{flex:0 0 260px;}
#gost58406_test4 .s42-note{flex:1 1 auto; min-width:260px;}
@media (max-width: 980px){
  #gost58406_test4 .s42-toprow{flex-direction:column; align-items:stretch;}
  #gost58406_test4 .s42-total,
  #gost58406_test4 .s42-type{flex:0 0 auto; width:100%;}
}
#gost58406_test4 td.s42-req.req-ok{background:#e9f7ef !important; border-color:#b9e5c7 !important;}
#gost58406_test4 td.s42-req.req-bad{background:#fdecec !important; border-color:#f3b7b7 !important;}


/* ===== 4.2 requirement column width & nowrap ===== */
#gost58406_test4 #tb42 td.s42-req{
  white-space: nowrap !important;
  text-align: center !important;
  font-variant-numeric: tabular-nums;
}


/* ===== 4.2 requirement column: make cell full width ===== */
#gost58406_test4 #tb42 td.s42-req-td{padding:6px 8px !important;}
#gost58406_test4 #tb42 td.s42-req-td .s42_req{
  display:block !important;
  width:100% !important;
  min-width:0 !important;
  white-space: nowrap !important;
  text-align:center !important;
}


/* ===== 4.2: auto residue (<0.063) is calculated (non-editable) ===== */
#gost58406_test4 #tb42 .s42_g_auto{width:100%;}


/* ===== 4.2 requirement coloring fix ===== */
#gost58406_test4 .s42_req.req-ok{
  background:#e9f7ef !important;
  border:1px solid #b9e5c7 !important;
}
#gost58406_test4 .s42_req.req-bad{
  background:#fdecec !important;
  border:1px solid #f3b7b7 !important;
}



#gost58406_test4 #s42_note_status.s42-auto{color:#0a7a2f;}
#gost58406_test4 #s42_note_status.s42-manual{color:#b00020;}


/* ===== 4.2 total status note (background color) ===== */
#gost58406_test4 #s42_note_status{
  display:block;
  font-weight:600;
  color:#000 !important;
}
#gost58406_test4 .note.s42-auto{
  background:#e9f7ef !important;
  border-left:4px solid #0a7a2f !important;
}
#gost58406_test4 .note.s42-manual{
  background:#fdecec !important;
  border-left:4px solid #b00020 !important;
}


/* ===== TEST 3 manual input row ===== */
#gost58406_test3 input[type="number"]{
  width:100% !important;
  height:44px;
  border:1px solid #cbd6e2;
  border-radius:10px;
  padding:0 12px;
  font:inherit;
  outline:none;
}
#gost58406_test3 input[type="number"]:focus{
  border-color:#7aa7d9;
  box-shadow:0 0 0 3px rgba(58,132,203,.15);
}
