.sb-attachment-preview {
  position: fixed;
  inset: 0;
  z-index: 130000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 24, 32, .62);
  backdrop-filter: blur(3px);
}

.sb-attachment-preview[hidden] {
  display: none !important;
}

.sb-attachment-panel {
  width: min(1180px, 96vw);
  height: min(880px, 92vh);
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #d8d4ca;
  border-radius: 16px;
  background: #f8f6f0;
  box-shadow: 0 24px 70px rgba(3, 17, 24, .28);
}

.sb-attachment-head {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 14px 16px;
  border-bottom: 1px solid #ddd8ce;
  background: #fffdf8;
}

.sb-attachment-title {
  min-width: 0;
  flex: 1;
}

.sb-attachment-title strong,
.sb-attachment-title span {
  display: block;
}

.sb-attachment-title strong {
  overflow: hidden;
  color: #152d39;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-attachment-title span {
  margin-top: 2px;
  color: #61747d;
  font-size: 11px;
}

.sb-attachment-actions {
  display: flex;
  gap: 8px;
}

.sb-attachment-btn {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid #cfd9dc;
  border-radius: 9px;
  color: #244d4a;
  background: #fff;
  font: 600 12px/1 "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  cursor: pointer;
}

.sb-attachment-btn:hover {
  border-color: #7eb8ad;
  background: #f2faf8;
}

.sb-attachment-btn[disabled] {
  cursor: wait;
  opacity: .55;
}

.sb-attachment-body {
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: auto;
  background: #e9eceb;
}

.sb-attachment-body img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
}

.sb-attachment-body iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.sb-attachment-text {
  min-height: 100%;
  margin: 0;
  padding: 24px;
  color: #21383d;
  background: #fff;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.sb-attachment-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 28px;
  text-align: center;
  color: #5f706d;
}

.sb-attachment-state strong {
  color: #1d3b3c;
  font-size: 16px;
}

.sb-attachment-state p {
  max-width: 48ch;
  margin: 0;
  font-size: 12px;
  line-height: 1.65;
}

@media (max-width: 640px) {
  .sb-attachment-preview {
    padding: 8px;
  }

  .sb-attachment-panel {
    width: 100%;
    height: calc(100dvh - 16px);
    border-radius: 12px;
  }

  .sb-attachment-head {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 12px;
  }

  .sb-attachment-actions {
    width: 100%;
  }

  .sb-attachment-actions .sb-attachment-btn {
    flex: 1;
  }

  .sb-attachment-title strong {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

/* Shared attachment form. Kept here so every portal uses one upload surface. */
.finance-native-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.finance-file-field {
  position: relative;
}

.attachment-dropzone {
  min-height: 84px;
  display: grid;
  place-items: center;
  padding: 12px;
  border: 1px dashed #c9c5bb;
  border-radius: 10px;
  color: #62655c;
  background: #fcfbf7;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.attachment-dropzone:hover,
.attachment-dropzone:focus-visible,
.attachment-dropzone.dragging {
  border-color: #66988b;
  background: #f1f5f2;
  outline: none;
}

.attachment-dropzone.invalid {
  border-color: #b85b47;
  background: #fff7f3;
  box-shadow: 0 0 0 2px rgba(184, 91, 71, .08);
}

.attachment-dropzone-empty,
.attachment-dropzone-preview {
  width: 100%;
}

.attachment-dropzone-empty {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
}

.attachment-upload-mark {
  width: 20px;
  height: 20px;
  color: #52756b;
}

.attachment-upload-mark svg {
  width: 100%;
  height: 100%;
}

.attachment-dropzone-empty strong {
  color: #3f413b;
  font-size: 11px;
  font-weight: 500;
}

.attachment-dropzone-empty small,
.attachment-dropzone-preview small {
  color: #858176;
  font-size: 10px;
}

.attachment-dropzone-preview {
  display: block;
}

.attachment-dropzone-preview[hidden] {
  display: none;
}

.attachment-selected-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.attachment-selected-head strong {
  color: #3f413b;
  font-size: 11px;
  font-weight: 600;
}

.attachment-clear-all,
.attachment-selected-action {
  padding: 0;
  border: 0;
  color: #176f65;
  background: transparent;
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}

.attachment-clear-all:hover,
.attachment-selected-action:hover {
  color: #0b544d;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.attachment-selected-files {
  display: grid;
  gap: 6px;
}

.attachment-selected-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid #e0ddd4;
  border-radius: 9px;
  background: #fffefa;
}

.attachment-selected-thumb {
  width: 52px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 7px;
  background: #ece9e1;
  cursor: zoom-in;
}

.attachment-selected-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-selected-copy {
  min-width: 0;
}

.attachment-selected-copy strong,
.attachment-selected-copy small {
  display: block;
  overflow-wrap: anywhere;
}

.attachment-selected-copy strong {
  color: #303933;
  font-size: 11px;
  font-weight: 500;
}

.attachment-selected-copy small {
  margin-top: 2px;
  color: #858176;
  font-size: 10px;
}

.attachment-selected-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.attachment-dropzone-remove {
  border: 1px solid #d7d4ca;
  border-radius: 7px;
  padding: 5px 8px;
  color: #6d5c48;
  background: #fff;
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}

.attachment-file-mark {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  gap: 1px;
  color: #52756b;
  background: #eef3ef;
}

.attachment-file-mark svg {
  width: 18px;
  height: 18px;
}

.attachment-file-mark em {
  color: #61736d;
  font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  font-style: normal;
}

.sales-chain-proof-list {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

.sales-chain-proof-item {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.sales-chain-proof-item .attachment-link {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sales-chain-proof-grid {
  display: grid;
  gap: 8px;
}

.sales-chain-proof-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #dbe3e2;
  border-radius: 10px;
  background: #fbfcfa;
}

.sales-chain-proof-row > span {
  min-width: 0;
}

.sales-chain-proof-row strong,
.sales-chain-proof-row small {
  display: block;
}

.sales-chain-proof-row strong {
  color: #173a39;
  font-size: 12px;
  font-weight: 600;
}

.sales-chain-proof-row small {
  margin-top: 4px;
  color: #687b78;
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.sales-chain-proof-row.is-voided {
  opacity: .72;
  background: #f4f5f2;
}

.sales-chain-history {
  margin-top: 16px;
  padding: 12px 16px;
  border: 1px solid #dbe3e2;
  border-radius: 10px;
  background: #f8faf7;
}

.sales-chain-history summary {
  color: #355451;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.sales-chain-history .sales-chain-proof-grid {
  margin-top: 12px;
}

.finance-chain-filter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 8px;
  align-items: center;
}

.finance-chain-filter input,
.finance-chain-filter select {
  min-width: 0;
  min-height: 40px;
}

@media (max-width: 720px) {
  .attachment-selected-item {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .attachment-selected-thumb,
  .attachment-file-mark {
    width: 48px;
    height: 44px;
  }

  .attachment-selected-actions {
    grid-column: 2;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .sales-chain-proof-row,
  .finance-chain-filter {
    grid-template-columns: 1fr;
  }
}
