.po-fields {
  --frac-bg: color-mix(in srgb, var(--text) 7%, var(--surface));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.po-fields-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.po-fields-help {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.po-count-toggle,
.form-group label.po-count-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  min-height: 32px;
}

#inline-add-row > td.col-order {
  box-sizing: border-box;
  width: 320px;
  min-width: 240px;
  max-width: 320px;
  overflow: visible;
  vertical-align: top;
}

#inline-add-row .po-chip-row {
  max-width: 100%;
}

#inline-add-row .po-chip {
  max-width: 100%;
  white-space: normal;
}

#inline-add-row .po-add {
  min-width: 0;
  max-width: 100%;
  flex: 1 1 8rem;
}

#inline-add-row > td.col-ia-load,
#inline-add-row > td.col-ia-dc,
.board-scroll > table th.col-ia-load,
.board-scroll > table th.col-ia-dc {
  box-sizing: border-box;
  width: 6.5rem;
  min-width: 6.5rem;
  max-width: 6.5rem;
  vertical-align: top;
  overflow: visible;
}

#inline-add-row .ia-cell-fit {
  width: 0;
  min-width: 100%;
}

#inline-add-row .ia-cell-fit input,
#inline-add-row .ia-cell-fit select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

th.col-ia-load,
th.col-ia-dc {
  cursor: default;
}

.ia-struct-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.po-chip-row,
.po-review-pos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.po-chip,
.po-review-chip,
.po-add,
.po-mono,
.po-pop-skids,
.po-count-input {
  font-family: var(--font-num), sans-serif;
}

.po-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-strong, var(--border));
  background: var(--frac-bg);
  color: var(--purple);
  cursor: pointer;
}

.po-chip-master {
  border-width: 2px;
  border-color: var(--purple);
}

.po-chip-flagged,
.po-review-ambiguous,
.po-review-invalid input {
  border-style: dashed;
}

.po-chip-selected {
  background: var(--selected-bg);
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.po-chip:focus-visible,
.po-add:focus-visible,
.po-mono:focus-visible,
.po-pop-skids:focus-visible,
.po-remove:focus-visible,
.po-undo-btn:focus-visible,
.po-review-actions .btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.po-chip-bang {
  color: var(--field-error, var(--red));
  font-weight: 700;
}

.po-chip-check {
  font-size: 0.75rem;
}

.po-add,
.po-mono,
.po-pop-skids,
.po-count-input,
.po-review-chip input,
.po-review-invalid input,
.po-review-row input {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  min-height: 32px;
  box-sizing: border-box;
}

.po-add {
  min-width: 8rem;
  flex: 1;
}

.po-legacy {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.po-legacy-text {
  width: 100%;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.95rem;
}

.po-parse-btn {
  align-self: flex-start;
}

.po-add::placeholder {
  color: var(--muted);
}

.po-fields input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--surface2) inset;
}

.po-chip-wrap {
  position: relative;
  display: inline-flex;
}

.po-pop {
  position: absolute;
  z-index: 5;
  top: calc(100% + 8px);
  left: 0;
  right: auto;
  min-width: 220px;
  padding: 10px;
  border: 1px solid var(--border-strong, var(--border));
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body:not(.light-mode) .po-pop {
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}

.po-pop-above {
  top: auto;
  bottom: calc(100% + 8px);
}

.po-pop-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.po-pop-done {
  min-height: 36px;
}

.po-remove {
  align-self: flex-start;
  background: none;
  border: 0;
  padding: 6px 0;
  min-height: 32px;
  box-sizing: border-box;
  color: var(--red);
  cursor: pointer;
  font-size: 0.82rem;
}

.po-undo,
.po-skid-note,
.po-hint-line,
.po-error,
.po-review-note,
.po-review-found {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.po-undo,
.po-skid-note {
  color: color-mix(in srgb, var(--muted) 70%, var(--text));
}

.po-error {
  color: var(--field-error, var(--red));
}

.po-review-found {
  color: var(--text);
}

.po-undo-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--purple);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.po-extras {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.po-extras label,
.po-count-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.po-review {
  border: 1px solid var(--border-strong, var(--border));
  border-left: 4px solid var(--purple);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.po-review-title {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.po-review-row {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 8px;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.po-review-invalid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0;
  color: var(--field-error, var(--red));
  font-size: 0.8rem;
}

.po-review-invalid input,
.po-review-ambiguous {
  outline: 2px solid var(--field-error, var(--red));
}

.po-review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.po-fields-compact .po-extras {
  grid-template-columns: repeat(3, minmax(5rem, 1fr));
}

.po-fields-compact .po-fields-help {
  display: none;
}

@media (max-width: 480px) {
  .po-extras,
  .po-review-row {
    grid-template-columns: 1fr;
  }

  .po-chip-wrap {
    display: contents;
  }

  .po-pop {
    position: static;
    order: 2;
    flex: 1 0 100%;
    width: 100%;
    min-width: 0;
    margin-bottom: 0;
  }

  .po-chip {
    min-height: 48px;
    width: auto;
    flex: 0 1 auto;
  }

  .po-add {
    order: 1;
    flex: 1 0 100%;
  }

  .po-add,
  .po-mono,
  .po-legacy-text,
  .po-parse-btn,
  .po-pop-skids,
  .po-count-input,
  .po-pop-done,
  .po-review-actions .btn {
    min-height: 48px;
    width: 100%;
  }

  .po-review-actions {
    flex-direction: column;
  }

  .po-remove {
    min-height: 48px;
    margin-top: 8px;
    width: auto;
  }
}
