/**
 * Таблица черновика закрытия работ: только work_closure.html и work_writeoff_draft.html
 */
.groups-table th.col-num,
.groups-table td.col-num {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.draft-wrap table.items thead th.col-num,
.draft-wrap table.items td.num {
  text-align: right;
}

.draft-wrap table.items td.col-unit {
  text-align: left;
}

.draft-wrap table.items thead th.col-unit {
  text-align: left;
}

.draft-wrap table.items td.row-actions {
  text-align: center;
}

.draft-wrap table.items thead th.col-tight,
.draft-wrap table.items tbody td.col-tight {
  width: 0.01%;
  white-space: nowrap;
  padding-left: 4px;
  padding-right: 4px;
  vertical-align: middle;
}

.draft-wrap table.items td.col-tight .inp-sm,
.draft-wrap table.items td.col-tight .qty-write,
.draft-wrap table.items td.col-tight .work-qty,
.draft-wrap table.items td.col-tight .work-unitprice-inp {
  max-width: 4.5rem;
  min-width: 0;
  box-sizing: border-box;
}

tr.row-root td,
tr.row-work-step td {
  font-weight: 700;
}

tr.row-root .task-title,
tr.row-work-step .task-title {
  font-weight: 700;
}

tr.row-material td {
  font-weight: 400;
}

tr.row-material .mat-cell,
tr.row-material .mat-fixed {
  font-weight: 400;
}

tr.group-row {
  cursor: pointer;
  transition: background 0.12s ease;
}

tr.group-row:hover {
  background: var(--accent-soft);
}

tr.group-row.selected {
  background: rgba(29, 114, 210, 0.14);
  outline: 1px solid var(--border-hover);
}

.row-material td:nth-child(2) {
  padding-left: 10ch;
}

.mat-cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  min-width: 0;
}

.mat-cell.mat-cell-stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.mat-cell.mat-cell-stacked .mat-pick-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.mat-cell.mat-cell-stacked .mat-pick-row .mat-pick {
  flex: 1 1 auto;
}

.mat-plan-line {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  font-weight: 500;
}

.mat-cell .mat-pick {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  font-size: 11px;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.mat-cell .mat-refresh {
  flex: 0 0 auto;
  order: 2;
}

.mat-cell .mat-pick {
  order: 1;
}

select.unit-sel {
  max-width: 88px;
  min-width: 72px;
  font-size: 11px;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

#draftRows input[type="number"].inp-sm,
#draftRows input[type="number"].qty-write,
#draftRows input[type="number"].unitprice-inp {
  -moz-appearance: textfield;
  appearance: textfield;
}

#draftRows input[type="number"]::-webkit-outer-spin-button,
#draftRows input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.draft-wrap {
  overflow-x: auto;
}

.drag-col {
  width: 26px;
  padding: 4px 2px;
  text-align: center;
  vertical-align: middle;
}

.drag-col .drag-source {
  min-height: 28px;
  min-width: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  border-radius: 4px;
}

.drag-col .drag-source:hover {
  background: var(--accent-soft);
}

.drag-col .drag-source:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.drag-col .drag-source:active {
  cursor: grabbing;
}

.drag-handle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  letter-spacing: -1px;
  display: inline-block;
  padding: 2px 4px;
  border-radius: 4px;
  pointer-events: none;
}

tr.dragging-row {
  opacity: 0.45;
}

.draft-wrap--dragging {
  user-select: none;
}

.draft-wrap--dragging * {
  cursor: grabbing !important;
}

.closure-drop-line {
  position: fixed;
  height: 4px;
  margin-top: -2px;
  background: var(--accent);
  border-radius: 2px;
  /* Выше оверлея загрузки черновика (.draft-panel-loading-overlay z-index: 200), иначе линия не видна при commit */
  z-index: 250;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), 0 2px 8px rgba(29, 114, 210, 0.35);
  opacity: 0.95;
  display: none;
}

.closure-drop-line.is-visible {
  display: block;
}

/* Мобильная вёрстка: уместить название материала и «Списать», меньше отступ от шага */
@media (max-width: 640px) {
  body:has(#draftPanel) {
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
  }

  #draftPanel .panel-head h2#draftTitle {
    font-size: 1.05rem;
    line-height: 1.3;
  }

  .draft-wrap table.items {
    font-size: 11px;
  }

  .draft-wrap table.items thead th {
    font-size: 10px;
    padding: 6px 3px;
  }

  .draft-wrap table.items tbody td {
    padding: 5px 3px;
  }

  .drag-col {
    width: 20px;
    padding: 2px 0;
  }

  .drag-col .drag-source {
    min-width: 16px;
    min-height: 22px;
  }

  .drag-handle {
    font-size: 10px;
    padding: 1px 2px;
  }

  /* Шаг / корень: чуть от ручки; материалы — небольшой, но заметный отступ от шага (не как 10ch на десктопе) */
  tr.row-work-step td:nth-child(2),
  tr.row-root td:nth-child(2) {
    padding-left: 4px;
  }

  .row-material td:nth-child(2) {
    padding-left: 14px;
  }

  .mat-plan-line {
    font-size: 10px;
    line-height: 1.3;
  }

  .mat-cell.mat-cell-stacked {
    gap: 2px;
  }

  .mat-cell .mat-pick {
    font-size: 10px;
    padding-right: 18px;
    background-position: right 4px center;
  }

  select.unit-sel {
    min-width: 52px;
    max-width: 76px;
    font-size: 10px;
    padding: 3px 16px 3px 4px;
  }

  .draft-wrap table.items td.col-tight .inp-sm,
  .draft-wrap table.items td.col-tight .qty-write,
  .draft-wrap table.items td.col-tight .work-qty,
  .draft-wrap table.items td.col-tight .work-unitprice-inp {
    max-width: 3.25rem;
    font-size: 10px;
    padding: 4px 4px;
  }

  td.muted {
    font-size: 10px;
  }

  button.icon-btn {
    padding: 2px 5px;
    font-size: 12px;
  }

  #draftPanel .toolbar {
    padding-left: 10px;
    padding-right: 10px;
    gap: 6px;
  }

  #draftPanel .toolbar button {
    font-size: 13px;
    padding: 7px 8px;
  }
}

/* Загрузка черновика: оверлей на #draftPanel (work_closure + work_writeoff) */
#draftPanel {
  position: relative;
}

#draftPanel.draft-panel--loading {
  pointer-events: none;
}

#draftPanel.draft-panel--loading .draft-panel-loading-overlay {
  pointer-events: auto;
}

/* Важно: без [hidden] авторский display:flex перебивает поведение атрибута hidden — оверлей остаётся видимым после endDraftPanelLoading */
.draft-panel-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  background: rgba(255, 255, 255, 0.72);
  border-radius: inherit;
  backdrop-filter: blur(2px);
}

.draft-panel-loading-overlay[hidden] {
  display: none !important;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .draft-panel-loading-overlay {
    background: rgba(22, 24, 28, 0.78);
  }
}

.draft-panel-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border, #d0d4dc);
  border-top-color: var(--accent, #1d72d2);
  border-radius: 50%;
  animation: draft-panel-spin 0.75s linear infinite;
}

@keyframes draft-panel-spin {
  to {
    transform: rotate(360deg);
  }
}

.draft-panel-loading-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
