.collage-panel { max-width: 1180px; }
.collage-section + .collage-section { border-top: 1px solid var(--line); margin-top: 26px; padding-top: 26px; }
.collage-section[hidden], .custom-size[hidden] { display: none; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.section-head h2 { font-size: 1.12rem; margin: 0 0 4px; }
.section-head p { color: var(--muted); font-size: .84rem; margin: 0; }
.optional { display: inline-block; border-radius: 999px; color: var(--muted); background: var(--dropzone); font-size: .66rem; font-weight: 700; padding: 4px 8px; vertical-align: 2px; }
.count-filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 10px; }
.count-chip { flex: 0 0 auto; min-width: 38px; height: 34px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink-soft); background: var(--surface); cursor: pointer; font: inherit; font-size: .78rem; font-weight: 700; }
.count-chip:hover, .count-chip.on { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.count-chip:disabled { opacity: .35; cursor: not-allowed; }
.template-grid { display: grid; grid-template-columns: repeat(8, minmax(92px, 1fr)); gap: 10px; max-height: 420px; overflow-y: auto; padding: 2px; }
.template-card { display: grid; gap: 7px; min-width: 0; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-soft); background: var(--surface); padding: 8px; cursor: pointer; font: inherit; text-align: left; }
.template-card:hover { border-color: var(--brand); transform: translateY(-1px); }
.template-card.on { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(109,94,252,.18); }
.template-card:disabled { opacity: .38; cursor: not-allowed; transform: none; }
.template-preview { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 7px; background: var(--dropzone); }
.template-frame { position: absolute; border: 1px solid var(--surface); border-radius: 2px; background: linear-gradient(135deg, rgba(109,94,252,.8), rgba(20,200,178,.75)); }
.template-card span:last-child { overflow: hidden; font-size: .7rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.template-status { color: var(--muted); font-size: .78rem; margin: 12px 0 0; }
.collage-dropzone { padding: 38px 20px; }
.pending-photo { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--dropzone); margin-top: 12px; padding: 9px; }
.pending-photo[hidden] { display: none; }
.pending-photo img { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; }
.pending-photo span { flex: 1; min-width: 0; overflow: hidden; color: var(--ink-soft); font-size: .8rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.workspace-head { align-items: center; }
.collage-workspace { display: grid; grid-template-columns: 210px minmax(300px, 1fr) 210px; gap: 18px; align-items: start; }
.collage-settings, .photo-settings { display: grid; gap: 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--dropzone); padding: 14px; }
.collage-settings h3, .photo-settings h3, .photo-tray-wrap h3 { font-size: .9rem; margin: 0; }
.collage-settings h3:not(:first-child) { border-top: 1px solid var(--line); margin-top: 3px; padding-top: 14px; }
.collage-settings .field select, .photo-settings .field select { width: 100%; }
.custom-size { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.custom-size input { width: 100%; }
.range-field { display: grid; gap: 7px; }
.range-field > span { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-soft); font-size: .76rem; font-weight: 700; }
.range-field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.range-field input { width: 100%; accent-color: var(--brand); }
.color-field { display: grid; grid-template-columns: 1fr auto; align-items: center; }
.color-field label { grid-column: 1 / -1; }
.color-field input { width: 44px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 2px; cursor: pointer; }
.color-field output { color: var(--muted); font-size: .74rem; font-weight: 700; }
.settings-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.settings-row select { width: 100%; }
.collage-stage-column { min-width: 0; }
.collage-stage { display: grid; place-items: center; min-height: 440px; overflow: auto; border-radius: 14px; background: repeating-conic-gradient(rgba(128,128,128,.13) 0 25%, transparent 0 50%) 50% / 18px 18px; padding: 16px; }
#collageCanvas { display: block; max-width: 100%; max-height: 620px; background: #fff; box-shadow: 0 14px 38px rgba(20,24,50,.24); cursor: pointer; touch-action: none; }
#collageCanvas.dragging { cursor: grabbing; }
#collageCanvas:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
.canvas-help { color: var(--muted); font-size: .75rem; text-align: center; margin: 9px 0 0; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-actions .btn { padding: 9px 8px; font-size: .76rem; }
.photo-actions .danger { grid-column: 1 / -1; color: #dc2626; }
.photo-quality { color: #b45309; background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.35); border-radius: 9px; font-size: .74rem; margin: 0; padding: 9px; }
.photo-quality[hidden] { display: none; }
.photo-tray-wrap { display: flex; align-items: flex-start; gap: 18px; border-top: 1px solid var(--line); margin-top: 18px; padding-top: 18px; }
.photo-tray-wrap > div:first-child { flex: 0 0 160px; }
.photo-tray-wrap p { color: var(--muted); font-size: .72rem; margin: 4px 0 0; }
.photo-tray { display: flex; gap: 9px; min-width: 0; overflow-x: auto; padding: 2px 2px 8px; }
.photo-thumb { position: relative; flex: 0 0 68px; height: 68px; overflow: hidden; border: 2px solid transparent; border-radius: 10px; background: var(--dropzone); padding: 0; cursor: grab; }
.photo-thumb.on { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(109,94,252,.18); }
.photo-thumb.drag-over { border-color: var(--ok); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.photo-thumb span { position: absolute; left: 4px; top: 4px; display: grid; place-items: center; width: 19px; height: 19px; border-radius: 50%; color: #fff; background: rgba(0,0,0,.65); font-size: .66rem; font-weight: 800; pointer-events: none; }
.collage-actions { display: flex; align-items: center; gap: 14px; margin-top: 20px; }
.collage-actions p { color: var(--muted); font-size: .8rem; margin: 0; }
.collage-result { text-align: center; }
.collage-result img { display: block; max-width: min(100%, 720px); max-height: 620px; object-fit: contain; border-radius: 10px; background: #fff; box-shadow: 0 12px 34px rgba(20,24,50,.2); margin: 0 auto 18px; }
.collage-result .actions { justify-content: center; }

@media (max-width: 1040px) {
  .template-grid { grid-template-columns: repeat(6, minmax(88px, 1fr)); }
  .collage-workspace { grid-template-columns: 190px minmax(280px, 1fr); }
  .photo-settings { grid-column: 1 / -1; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
  .photo-settings h3 { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .section-head, .workspace-head, .photo-tray-wrap { flex-direction: column; }
  .template-grid { grid-template-columns: repeat(3, minmax(86px, 1fr)); max-height: 390px; }
  .collage-workspace { grid-template-columns: 1fr; }
  .collage-stage-column { order: -1; }
  .collage-stage { min-height: 320px; padding: 10px; }
  #collageCanvas { max-height: 500px; }
  .photo-settings { grid-column: auto; grid-template-columns: 1fr; }
  .photo-settings h3 { grid-column: auto; }
  .photo-tray-wrap > div:first-child { flex-basis: auto; }
  .collage-actions { align-items: flex-start; flex-direction: column; }
}
