.cp-manager {
  display: grid;
  gap: 22px;
  container: portfolio-manager / inline-size;
}

.cp-manager-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 28px;
}

.cp-manager-head h2,
.cp-public-card h3,
.cp-empty h3 { margin: 0; color: var(--ink, #26241f); }
.cp-manager-head > p { max-width: 430px; margin: 0; color: #52645a; line-height: 1.65; }

.cp-upload {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 22px;
  border: 1px solid #dce7e1;
  border-radius: 14px;
  background: #f7faf8;
}

.cp-upload .is-wide { grid-column: 1 / -1; }
.cp-upload > .cs-btn { justify-self: start; }
.cp-visibility { display: flex; min-height: 44px; align-items: center; gap: 10px; color: var(--ink, #26241f); font-weight: 700; }
.cp-visibility input { width: 18px; height: 18px; accent-color: var(--green, #2b3f32); }
.cp-feedback { min-height: 24px; margin: -6px 0 0; color: #52645a; }
.cp-feedback.is-error { color: #c5221f; }

.cp-manager-list { display: grid; gap: 16px; margin: 0; padding: 0; list-style: none; }
.cp-manager-item { display: grid; grid-template-columns: minmax(180px, 240px) minmax(0, 1fr); gap: 22px; padding: 18px; border: 1px solid #dce7e1; border-radius: 14px; }
.cp-preview-wrap { width: min(100%, 184px); min-width: 0; align-self: start; }
.cp-preview { display: grid; width: 100%; max-height: 260px; aspect-ratio: 210 / 297; place-items: center; overflow: hidden; border: 1px solid #dce7e1; border-radius: 10px; background: #fff; color: #52645a; }
.cp-preview canvas,
.cp-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
.cp-file-meta { margin: 8px 0 0; color: #52645a; font-size: 13px; line-height: 1.45; }
.cp-manager-fields,
.cp-manager-fields .cs-field { display: grid; min-width: 0; gap: 12px; }
.cp-manager-fields .cs-input,
.cp-manager-fields .cs-textarea { box-sizing: border-box; width: 100%; min-width: 0; }
.cp-item-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cp-item-actions > * { max-width: 100%; }
.cp-item-actions .is-danger { color: #c5221f; }
.cp-delete-confirm { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid #d8a7a5; border-radius: 10px; background: #fff; }
.cp-delete-confirm p { margin: 0; color: #7f2420; font-size: 14px; line-height: 1.5; }
.cp-delete-confirm > div { display: flex; flex: 0 0 auto; gap: 8px; }
.cp-delete-confirm [data-delete-confirm] { border-color: #c5221f; background: #c5221f; color: #fff; }
.cp-empty { padding: 28px; border: 1px dashed #dce7e1; border-radius: 14px; text-align: center; }
.cp-empty p { margin: 8px 0 0; color: #52645a; }

.cp-public-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.cp-public-card { overflow: hidden; border: 1px solid #dce7e1; border-radius: 14px; background: #fff; }
.cp-public-preview { position: relative; display: block; width: 100%; min-height: 220px; padding: 0; overflow: hidden; border: 0; border-bottom: 1px solid #dce7e1; background: #edf2ef; cursor: pointer; }
.cp-public-preview img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; object-position: center; }
.cp-public-preview span { position: absolute; right: 12px; bottom: 12px; padding: 9px 12px; border-radius: 10px; background: var(--green, #2b3f32); color: #fff; font-weight: 700; }
.cp-public-card > div { padding: 18px; }
.cp-public-card p { margin: 8px 0 14px; color: #52645a; line-height: 1.65; }
.cp-public-card a { color: var(--green-d, #21302a); font-weight: 700; text-underline-offset: 3px; }

.cp-viewer[hidden] { display: none; }
.cp-viewer { margin-top: 22px; }
.cp-viewer-panel { width: 100%; border: 1px solid #dce7e1; border-radius: 14px; background: #fff; }
.cp-viewer-head,
.cp-viewer-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; }
.cp-viewer-head { border-bottom: 1px solid #dce7e1; }
.cp-viewer-head h2 { margin: 0; font-size: 20px; }
.cp-viewer-stage { display: grid; min-height: 440px; place-items: center; padding: 20px; background: #edf2ef; }
.cp-viewer-stage canvas,
.cp-viewer-stage img { display: block; max-width: 100%; height: auto; }
.cp-viewer-actions { border-top: 1px solid #dce7e1; }
.cp-viewer-actions > div { display: flex; align-items: center; gap: 10px; }
.cp-viewer button,
.cp-viewer a[data-viewer-download] {
  display: inline-flex;
  min-height: 40px;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  padding: 12px 14px;
  border: 1px solid #dce7e1;
  border-radius: 10px;
  background: #fff;
  color: #21302a;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}
.cp-viewer a[data-viewer-download] { border-color: #2b3f32; background: #2b3f32; color: #fff; }
.cp-viewer button:hover { border-color: #2b3f32; background: #edf2ef; }
.cp-viewer a[data-viewer-download]:hover { background: #21302a; }
.cp-viewer button:focus-visible,
.cp-viewer a[data-viewer-download]:focus-visible { outline: 3px solid rgba(43, 63, 50, .28); outline-offset: 2px; }
.cp-viewer button:disabled { border-color: #dce7e1; background: #edf2ef; color: #76837c; cursor: not-allowed; opacity: .72; }

@media (max-width: 768px) {
  .cp-manager-head { display: grid; gap: 8px; }
  .cp-upload,
  .cp-manager-item,
  .cp-public-gallery { grid-template-columns: 1fr; }
  .cp-preview { min-height: 160px; }
  .cp-viewer-stage { min-height: 55vh; padding: 12px; }
}

@container portfolio-manager (max-width: 620px) {
  .cp-manager-item { grid-template-columns: minmax(0, 1fr); }
  .cp-preview-wrap { justify-self: start; }
  .cp-delete-confirm { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .cp-public-preview span { transition: none; }
}

/* Portfolio management only; public gallery and viewer retain marketplace styling. */
.cs-ready-workspace-page .cp-manager :where(
  .cp-upload, .cp-manager-item, .cp-preview, .cp-delete-confirm, .cp-empty,
  .cs-btn, .cs-input, .cs-textarea
) {
  border-radius: var(--workspace-radius, 0);
  box-shadow: var(--workspace-shadow, none);
}
