.te-editor {
  --te-ink: var(--td-ink, #23333a);
  --te-muted: var(--td-muted, #56666a);
  --te-accent: var(--td-accent, #165d58);
  --te-border: var(--td-border, #d7dfda);
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 30px;
  color: var(--te-ink);
  font: inherit;
  text-align: start;
  container-type: inline-size;
}

.te-editor [hidden] {
  display: none !important;
}

.te-section {
  display: grid;
  min-width: 0;
  gap: 16px;
  margin: 0;
  padding: 0;
}

.te-editor .te-section-title {
  margin: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--te-border);
  color: var(--te-ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
}

.te-grid,
.te-parties {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 13px 16px;
  min-width: 0;
}

.te-parties {
  gap: 24px;
}

.te-party,
.te-logo,
.te-pack-fields,
.te-products,
.te-item-body {
  display: grid;
  min-width: 0;
  gap: 14px;
}

.te-party + .te-party {
  padding-left: 22px;
  border-left: 1px solid var(--te-border);
}

.te-subtitle,
.te-item-number {
  margin: 0;
  color: var(--te-ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
}

.te-subtitle {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.te-role-en,
.te-translation {
  color: var(--te-muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.3;
}

.te-field {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: 5px;
}

.te-wide,
.te-party > .te-grid > .te-field {
  grid-column: 1 / -1;
}

.te-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 7px;
  color: var(--te-ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.te-editor .te-input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  height: 40px;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid #b9c6c2;
  border-radius: 5px;
  background: #fff;
  color: var(--te-ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.te-input[type="number"] {
  appearance: textfield;
}

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

.te-input::placeholder {
  color: #687672;
  opacity: 1;
}

.te-editor textarea.te-input {
  min-height: 64px;
  height: auto;
  resize: vertical;
}

.te-field:focus-within .te-label {
  color: var(--te-accent);
}

.te-input:focus {
  border-color: var(--te-accent);
  outline: 2px solid #8ebbb4;
  outline-offset: 1px;
}

.te-details {
  min-width: 0;
  border-top: 1px solid var(--te-border);
}

.te-summary {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 5px 2px;
  color: var(--te-accent);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  list-style: none;
  cursor: pointer;
}

.te-summary::-webkit-details-marker {
  display: none;
}

.te-summary::before {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  content: "";
  transform: rotate(-45deg);
}

.te-details[open] > .te-summary::before {
  transform: rotate(45deg);
}

.te-details[open] > * + *,
.te-logo-preview {
  margin-top: 8px;
}

.te-logo {
  gap: 4px;
}

.te-editor .te-logo-file {
  width: 100%;
  min-width: 0;
  color: var(--te-muted);
  font: inherit;
  font-size: 12px;
}

.te-logo-file::file-selector-button {
  margin: 2px 8px 2px 1px;
  padding: 6px 9px;
  border: 1px solid #aabeb6;
  border-radius: 4px;
  background: #f2f6f2;
  color: var(--te-accent);
  font: inherit;
  cursor: pointer;
}

.te-logo-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.te-logo-preview img {
  display: block;
  width: auto;
  max-width: min(125px, 100%);
  height: 42px;
  object-fit: contain;
}

.te-hint,
.te-empty {
  margin: 0;
  color: var(--te-muted);
  font-size: 13px;
  line-height: 1.55;
}

.te-qty-hint {
  color: #805432;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}

.te-editor .te-input[aria-invalid="true"] {
  border-color: #996d4c;
}

.te-empty {
  padding: 12px;
  border: 1px dashed var(--te-border);
  border-radius: 6px;
  text-align: center;
}

.te-item {
  min-width: 0;
  border: 1px solid var(--te-border);
  border-radius: 7px;
  background: #fff;
}

.te-item-head,
.te-item-title,
.te-item-actions,
.te-select {
  display: flex;
  align-items: center;
}

.te-item-head {
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 5px 12px;
  min-height: 43px;
  padding: 5px 12px;
  border-radius: 6px 6px 0 0;
  background: #f0f4ef;
}

.te-item-title,
.te-item-actions {
  min-width: 0;
  gap: 10px;
}

.te-item-title {
  flex: 1 1 100px;
}

.te-item-number {
  flex: none;
}

.te-item-name {
  overflow: hidden;
  color: var(--te-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.te-item-body {
  padding: 15px;
}

.te-select {
  gap: 5px;
  min-height: 32px;
  color: var(--te-ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.te-select input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--te-accent);
}

.te-pack-fields {
  padding-top: 13px;
  border-top: 1px solid var(--te-border);
}

.te-pack-fields > .te-details > .te-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: 10px;
}

.te-computed {
  display: block;
  color: var(--te-accent);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

.te-editor .te-remove,
.te-editor .te-text-button,
.te-editor .te-add {
  width: fit-content;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--te-accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.te-editor .te-remove {
  padding: 4px;
  color: #765041;
  font-size: 12px;
}

.te-remove:hover,
.te-text-button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.te-editor .te-add {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid #819d92;
  border-radius: 5px;
  font-weight: 600;
}

.te-add::before {
  width: 12px;
  height: 12px;
  background: linear-gradient(currentColor, currentColor) center / 10px 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) center / 1.5px 10px no-repeat;
  content: "";
}

.te-add:hover {
  border-color: var(--te-accent);
  background: #eaf1eb;
}

.te-editor :is(button, summary, .te-select input, .te-logo-file):focus-visible {
  outline: 2px solid var(--te-accent);
  outline-offset: 2px;
}

@container (min-width: 740px) {
  .te-section > .te-grid,
  .te-item-body > .te-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .te-pack-fields > .te-grid,
  .te-section > .te-pack-totals {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@container (max-width: 560px) {
  .te-parties {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .te-party + .te-party {
    padding: 14px 0 0;
    border-top: 1px solid var(--te-border);
    border-left: 0;
  }
}

@container (max-width: 400px) {
  .te-section {
    gap: 12px;
  }

  .te-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .te-pack-fields > .te-grid,
  .te-pack-fields > .te-details > .te-per-carton,
  .te-pack-totals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 10px;
  }

  .te-per-carton > .te-field:first-child {
    grid-column: 1 / -1;
  }

  .te-pack-fields .te-translation,
  .te-pack-totals .te-translation {
    flex-basis: 100%;
  }

  .te-item-head {
    padding-inline: 8px;
  }

  .te-item-body {
    padding: 10px;
  }
}

@media (max-width: 800px), (pointer: coarse) {
  .te-editor {
    gap: 24px;
  }

  .te-editor .te-input {
    min-height: 43px;
    font-size: 16px;
  }
}
