/* SOP builder layout: header strip, three blocks, step grid, action bar and preview. */
.sop-strip {
  position: sticky;
  top: 0;
  z-index: 8;
  margin: 0 0 12px;
  padding: 10px 0 6px;
  border-bottom: 1px solid #cdd8c8;
  background: #f5f6ef;
}
.sop-strip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  align-items: center;
}
.sop-strip-title {
  flex: 1 1 320px;
  min-width: 0;
}
.sop-strip-title span,
.sop-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.sop-strip-title input {
  width: 100%;
  min-height: 46px;
  padding: 6px 10px;
  border: 1px solid #cdd8c8;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
}
.sop-strip-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 0;
}
.sop-strip-meta div {
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.sop-strip-meta dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sop-strip-meta dd {
  margin: 0;
  font-weight: 600;
}
.sop-status {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  background: #fff3d6;
  color: #6b4a00;
  font-size: 13px;
  font-weight: 600;
}
.sop-status.is-ready-review {
  background: #e6eee5;
  color: #24533b;
}
.sop-status.is-superseded {
  background: #e8e8e8;
  color: #444;
}
.sop-strip-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 4px;
}
.sop-strip-nav .text-button {
  min-height: 36px;
}
.sop-block-no {
  display: inline-grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  margin-right: 8px;
  border-radius: 50%;
  background: #24533b;
  color: #fff;
  font-size: 0.75em;
  font-weight: 700;
  vertical-align: 0.15em;
}
.sop-revision-details {
  margin-bottom: 16px;
}
#sop-block-1,
#sop-block-2,
#sop-block-3,
[data-sop-step-editor] {
  scroll-margin-top: 150px;
}

.sop-grid-wrap {
  max-width: 100%;
  overflow-x: auto;
}
.sop-grid {
  width: 100%;
  border-collapse: collapse;
}
.sop-grid th,
.sop-grid td {
  padding: 6px;
  border-bottom: 1px solid #e2e5dc;
  text-align: left;
  vertical-align: top;
}
.sop-grid thead th {
  color: #526854;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sop-grid tbody th {
  padding-top: 14px;
  font-variant-numeric: tabular-nums;
}
.sop-grid textarea {
  width: 100%;
  min-width: 160px;
  min-height: 64px;
  resize: vertical;
  font-size: 15px;
}
.sop-grid tr.is-current {
  background: #edf3ea;
}
.sop-grid tr.is-current th {
  box-shadow: inset 3px 0 0 #245c48;
}
.sop-grid-actions {
  white-space: nowrap;
}
.sop-grid-actions .button {
  min-height: 40px;
}
.sop-grid-actions [aria-pressed='true'] {
  border-color: #24533b;
  background: #e6eee5;
}
.sop-grid-actions .text-button {
  min-width: 36px;
  min-height: 40px;
}
.sop-step-details {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #cdd8c8;
  border-radius: 8px;
  background: #fff;
}
.sop-step-details:empty {
  display: none;
}
.sop-step-details h3 {
  margin-top: 0;
  overflow-wrap: anywhere;
}

.sop-actionbar {
  position: sticky;
  bottom: 0;
  z-index: 8;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding: 10px 16px;
  border: 1px solid #cdd8c8;
  border-radius: 10px 10px 0 0;
  background: #fff;
  box-shadow: 0 -4px 14px #0f2a2314;
}
.sop-saved {
  color: #24533b;
  font-size: 14px;
}
.sop-saved.is-error {
  color: #8a2f12;
  font-weight: 600;
}
.sop-actionbar-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sop-actionbar-buttons .button {
  min-height: 44px;
}

.sop-preview {
  width: min(960px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.sop-preview[open] {
  display: flex;
  flex-direction: column;
}
.sop-preview::backdrop {
  background: #0f2a2366;
}
.sop-preview > header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.sop-preview > header h2 {
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}
.sop-preview > header p {
  margin: 0;
}
.sop-preview-body {
  min-height: 0;
  overflow-y: auto;
  padding: 8px 20px 24px;
  overflow-wrap: anywhere;
}
.sop-preview-body h3 {
  margin: 24px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid #24533b;
}
.sop-preview-body h4 {
  margin: 14px 0 4px;
}
.sop-preview-missing {
  color: #8a2f12;
  font-style: italic;
}
.sop-preview-meta,
.sop-preview-step {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 6px 20px;
  margin: 8px 0;
}
.sop-preview-meta dt,
.sop-preview-step dt {
  color: var(--muted);
  font-size: 13px;
}
.sop-preview-meta dd,
.sop-preview-step dd {
  margin: 0;
}
.sop-preview-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.sop-preview-grid th,
.sop-preview-grid td {
  padding: 6px 8px;
  border: 1px solid #cdd8c8;
  text-align: left;
  vertical-align: top;
}
.sop-preview-grid thead th {
  background: #edf3ea;
}

/* Phones: grid rows become cards, the strip and bar tighten up. */
@media (max-width: 760px) {
  .sop-strip {
    padding: 6px 0 2px;
  }
  .sop-strip-row {
    gap: 4px;
  }
  .sop-strip-title {
    flex-basis: 100%;
  }
  .sop-strip-title input {
    min-height: 42px;
    font-size: 17px;
  }
  .sop-strip-meta {
    flex-wrap: nowrap;
    gap: 10px;
    font-size: 13px;
  }
  .sop-strip-meta dt {
    font-size: 10px;
  }
  .sop-strip-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-top: 0;
  }
  .sop-strip-nav .text-button {
    flex-shrink: 0;
    white-space: nowrap;
  }
  .sop-grid,
  .sop-grid tbody,
  .sop-grid tr,
  .sop-grid td,
  .sop-grid tbody th {
    display: block;
  }
  .sop-grid thead {
    display: none;
  }
  .sop-grid tr {
    margin-bottom: 12px;
    padding: 8px 10px;
    border: 1px solid #cdd8c8;
    border-radius: 8px;
  }
  .sop-grid td,
  .sop-grid tbody th {
    padding: 4px 0;
    border: 0;
  }
  .sop-grid tbody th::before {
    content: 'Step ';
  }
  .sop-grid td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: #526854;
    font-size: 13px;
  }
  .sop-grid textarea {
    min-width: 0;
  }
  .sop-grid tr.is-current th {
    box-shadow: none;
  }
  .sop-step-details {
    padding: 12px;
  }
  .sop-actionbar {
    padding: 8px 10px;
  }
  .sop-actionbar-buttons {
    width: 100%;
  }
  .sop-actionbar-buttons .button {
    flex: 1 1 auto;
    padding: 0 10px;
  }
  .sop-preview {
    width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }
  .sop-preview-grid {
    font-size: 13px;
  }
}

/* Make-room dialog shown when twelve revisions are stored. */
.sop-make-room {
  width: min(680px, calc(100vw - 32px));
}
.sop-room-list {
  max-height: 55vh;
  margin: 12px 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.sop-room-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #e2e5dc;
}
.sop-room-list li > div:first-child {
  display: grid;
  min-width: 0;
  overflow-wrap: anywhere;
}
.sop-room-list .export-actions {
  margin: 0;
}
.sop-room-note {
  min-height: 1.2em;
  margin: 4px 0;
  color: #24533b;
  font-weight: 600;
}

/* Drag to reorder: grip handle and drop indicator, shared by the step grid and the capture log. */
.drag-handle {
  display: inline-grid;
  place-items: center;
  width: 36px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #526854;
  font-size: 18px;
  letter-spacing: -1px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.drag-handle:hover,
.drag-handle:focus-visible {
  background: #e6eee5;
  color: #24533b;
}
.drag-handle:disabled {
  visibility: hidden;
}
.is-dragging {
  opacity: 0.55;
  background: #edf3ea;
}
.drop-before {
  box-shadow: inset 0 3px 0 #24533b;
}
.drop-after {
  box-shadow: inset 0 -3px 0 #24533b;
}
.sop-grid-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.sop-grid-tools .helper {
  margin: 0;
}
.sop-grid tbody th {
  white-space: nowrap;
}
.sop-grid tbody th .drag-handle {
  vertical-align: middle;
}
.sop-grid tbody th .sop-badge {
  display: block;
  width: max-content;
  margin-top: 4px;
}
.sop-grid.is-compact td,
.sop-grid.is-compact th {
  padding-top: 4px;
  padding-bottom: 4px;
}
.sop-grid-compact-title {
  width: 100%;
  font-weight: 600;
  vertical-align: middle !important;
  overflow-wrap: anywhere;
}
.sop-grid-actions .text-button {
  margin-left: 8px;
}
.sop-badge.is-field {
  background: #fff3d6;
  color: #6b4a00;
}
.sop-badge.is-drafted {
  background: #e6eee5;
  color: #24533b;
}
@media (max-width: 760px) {
  .sop-grid tbody th::before {
    content: none;
  }
  .sop-grid tbody th .sop-badge {
    display: inline-block;
    margin: 0 0 0 8px;
  }
}
@media (max-width: 760px) {
  .sop-grid.is-compact tr {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
    padding: 2px 8px 2px 2px;
  }
  .sop-grid.is-compact tbody th,
  .sop-grid.is-compact td {
    padding: 0;
  }
  .sop-grid.is-compact .sop-grid-compact-title {
    flex: 1;
    min-width: 0;
    font-size: 15px;
  }
  .sop-grid.is-compact .sop-grid-actions [data-grid-duplicate] {
    display: none;
  }
  .sop-grid.is-compact .sop-grid-actions .button {
    min-height: 40px;
    padding: 0 10px;
  }
  .sop-grid.is-compact tbody th .sop-badge {
    display: none;
  }
}
