/* reusable "Add to Collection" modal. inner geometry is in `--u` units where
   1u == 1 Figma px so the whole modal scales proportionally. */

.cm-no-scroll {
  overflow: hidden;
}

.cm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* barely-there dim, the blur does the work */
  background: rgba(0, 0, 0, 0.04);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--t-base) ease,
    visibility var(--t-base) ease;
}
.cm-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.cm-panel {
  --u: 0.0681198cqw; /* one Figma px of the 1468-wide panel */
  --line: #afafaf; /* divider rules + checkbox outline */
  container-type: inline-size;
  width: min(1468px, calc(100vw - 48px));
  /* sizes to header + (up to 4) rows + footer, capped to viewport; list scrolls
     past 4 rows. */
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  /* frosted translucent tint, lets the blurred page bleed through */
  background: linear-gradient(
    347deg,
    rgba(0, 0, 0, 0.62) 0%,
    rgba(10, 10, 10, 0.62) 20%,
    rgba(34, 34, 34, 0.62) 42%,
    rgba(60, 60, 60, 0.62) 62%,
    rgba(88, 88, 88, 0.62) 80%,
    rgba(116, 116, 116, 0.62) 92%,
    rgba(132, 132, 132, 0.62) 100%
  );
  border-radius: 16px;
  overflow: hidden;
  color: #f0f0f0;
  transform: translateY(16px) scale(0.985);
  transition: transform var(--t-base) var(--ease-pop);
}
.cm-overlay.is-open .cm-panel {
  transform: none;
}

.cm-header {
  position: relative;
  flex: 0 0 calc(127 * var(--u));
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: calc(2 * var(--u)) solid var(--line);
}
.cm-title {
  margin: 0;
  font-weight: 400;
  font-size: calc(55 * var(--u));
  line-height: 1;
  color: #f0f0f0;
  /* the font centres a touch high, nudge to baseline */
  transform: translateY(calc(6 * var(--u)));
}
.cm-close {
  position: absolute;
  top: calc(37 * var(--u));
  right: calc(46 * var(--u));
  width: calc(23 * var(--u));
  height: calc(23 * var(--u));
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 0.92;
  transition: opacity var(--t-base) ease;
}
.cm-close:hover {
  opacity: 1;
}
.cm-close::before,
.cm-close::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(32 * var(--u));
  height: calc(2.5 * var(--u));
  background: #f3f3f3;
  border-radius: 2px;
}
.cm-close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}
.cm-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* two collections per row; centre rule sits at x=776, not dead centre */
.cm-list {
  /* up to 4 rows; rows stretch (116u floor + 1fr) so grid lines reach the
     bottom edge. scrolls past 4 rows. */
  flex: 0 1 auto;
  height: calc(4 * 116 * var(--u));
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: calc(776 * var(--u)) 1fr;
  grid-auto-rows: minmax(calc(116 * var(--u)), 1fr);
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--pink), 0.18) rgba(0, 0, 0, 0.25);
}
.cm-list::-webkit-scrollbar {
  width: 14px;
}
.cm-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  margin: 6px 0;
}
.cm-list::-webkit-scrollbar-thumb {
  background: rgba(var(--pink), 0.18);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
.cm-list::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--pink), 0.26);
}

.cm-empty {
  grid-column: 1 / -1;
  padding: 40px 32px;
  text-align: center;
  color: #d8d8d8;
  font-size: clamp(16px, calc(28 * var(--u)), 28px);
}

.cm-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: calc(32 * var(--u));
  min-width: 0;
  padding: 0 calc(6 * var(--u)) 0 calc(59 * var(--u));
  border: none;
  background: transparent;
  color: #f0f0f0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-base) ease;
}
.cm-item:nth-child(odd):not(:last-child) {
  border-right: calc(2 * var(--u)) solid var(--line);
}
.cm-item:nth-child(even) {
  gap: calc(33 * var(--u));
  padding-left: calc(40 * var(--u));
  padding-right: calc(34 * var(--u));
}
.cm-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
/* inset horizontal rule between rows; last row drops it (footer's top border
   draws that line instead). */
.cm-item::after {
  content: "";
  position: absolute;
  bottom: calc(-1 * var(--u));
  height: calc(2 * var(--u));
  background: var(--line);
  pointer-events: none;
}
.cm-item:nth-child(odd)::after {
  left: calc(17 * var(--u));
  right: 0;
}
.cm-item:nth-child(even)::after {
  left: 0;
  right: calc(17 * var(--u));
}
/* last item has no bottom divider. in two-column layout the second-to-last
   shares the last row when the count is even, so drop its divider too. */
.cm-item:nth-last-child(1)::after {
  display: none;
}
@media (min-width: 761px) {
  .cm-item:nth-last-child(2):nth-child(odd)::after {
    display: none;
  }
}


.cm-check {
  flex: 0 0 auto;
  width: calc(40 * var(--u));
  height: calc(40 * var(--u));
  border-radius: 0;
  border: calc(3 * var(--u)) solid var(--line);
  background: rgba(217, 217, 217, 0.1);
  position: relative;
  transition:
    background-color var(--t-fast) ease,
    border-color var(--t-fast) ease;
}
.cm-item.is-selected .cm-check {
  background: #ffffff;
}
.cm-item.is-selected .cm-check::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  /* taller than wide: right border is the long up-stroke, bottom the short one */
  width: calc(12 * var(--u));
  height: calc(22 * var(--u));
  border: solid #afafaf;
  border-width: 0 calc(4 * var(--u)) calc(4 * var(--u)) 0;
  transform: translate(-50%, -58%) rotate(45deg);
}
.cm-name {
  flex: 0 1 auto;
  min-width: 0;
  font-size: calc(40 * var(--u));
  line-height: 1.05;
  color: #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* shared profile-style collage, sized by height so its 2:3 aspect stays intact */
.cm-item .collection-cover {
  flex: 0 0 auto;
  margin-left: auto;
  height: calc(88 * var(--u));
  width: auto;
  aspect-ratio: 2 / 3;
  border-radius: calc(3 * var(--u));
}
/* empty cover shows just the checkerboard here, the "+" is profile-only */
.cm-item .cover-empty__plus {
  display: none;
}

/* odd count: centre the lone last one across the full width (two-column only) */
@media (min-width: 761px) {
  .cm-item:nth-child(odd):nth-last-child(1) {
    grid-column: 1 / -1;
    justify-content: center;
    padding-left: calc(59 * var(--u));
    padding-right: calc(59 * var(--u));
    border-right: none;
  }
  .cm-item:nth-child(odd):nth-last-child(1) .collection-cover {
    margin-left: 0;
  }
}

.cm-footer {
  position: relative;
  flex: 0 0 calc(156 * var(--u));
  border-top: calc(2 * var(--u)) solid var(--line);
}
.cm-newlabel {
  position: absolute;
  left: calc(146 * var(--u));
  top: 50%;
  transform: translateY(-50%);
  font-size: calc(40 * var(--u));
  color: #f0f0f0;
  white-space: nowrap;
}
.cm-newfield {
  position: absolute;
  left: calc(463 * var(--u));
  top: 50%;
  transform: translateY(-50%);
  width: calc(700 * var(--u));
  height: calc(70 * var(--u));
}
.cm-input {
  width: 100%;
  height: 100%;
  padding: 0 calc(28 * var(--u));
  border: none;
  border-radius: calc(16 * var(--u));
  background: rgba(255, 136, 179, 0.18);
  color: #f0f0f0;
  font-family: inherit;
  font-size: calc(30 * var(--u));
  outline: none;
  transition: background var(--t-base) ease;
}
.cm-input::placeholder {
  color: rgba(240, 240, 240, 0.5);
}
.cm-input:focus {
  background: rgba(255, 136, 179, 0.26);
}
.cm-add {
  position: absolute;
  left: calc(1188 * var(--u));
  top: 50%;
  transform: translateY(-50%);
  width: calc(48 * var(--u));
  height: calc(48 * var(--u));
  padding: 0;
  border-radius: 50%;
  border: calc(2 * var(--u)) solid #f3f3f3;
  background: transparent;
  cursor: pointer;
  transition:
    background-color var(--t-base) ease,
    transform var(--t-fast) var(--ease-snap);
}
.cm-add:hover {
  background: rgba(255, 255, 255, 0.12);
}
.cm-add:active {
  transform: translateY(-50%) scale(0.92);
}
.cm-add::before,
.cm-add::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: #f3f3f3;
  border-radius: 2px;
}
.cm-add::before {
  width: calc(22 * var(--u));
  height: calc(2.5 * var(--u));
  transform: translate(-50%, -50%);
}
.cm-add::after {
  width: calc(2.5 * var(--u));
  height: calc(22 * var(--u));
  transform: translate(-50%, -50%);
}

/* phone: drop the fixed geometry for a stacked layout */
@media (max-width: 760px) {
  .cm-panel {
    container-type: normal;
    width: 100%;
    aspect-ratio: auto;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    border-radius: 14px;
  }
  .cm-header {
    flex: 0 0 auto;
    padding: 16px;
  }
  .cm-title {
    font-size: clamp(22px, 6vw, 30px);
  }
  .cm-close {
    width: 24px;
    height: 24px;
    top: 14px;
    right: 16px;
  }
  .cm-close::before,
  .cm-close::after {
    width: 26px;
    height: 2.5px;
  }
  .cm-list {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
    /* single column fills the screen and scrolls (cqw/--u resolve tiny here) */
    flex: 1 1 auto;
    height: auto;
  }
  /* equal full-width rows + dividers; match the base nth-child specificity so
     these win on source order instead of needing !important. */
  .cm-item:nth-child(odd),
  .cm-item:nth-child(even) {
    gap: 14px;
    padding: 14px 16px;
  }
  .cm-item:nth-child(odd):not(:last-child) {
    border-right: none;
  }
  .cm-item::after {
    height: 1px;
  }
  .cm-item:nth-child(odd)::after,
  .cm-item:nth-child(even)::after {
    left: 0;
    right: 0;
  }
  .cm-check {
    width: 26px;
    height: 26px;
    border-width: 2px;
    border-radius: 0;
    background: rgba(217, 217, 217, 0.1);
  }
  .cm-item.is-selected .cm-check::after {
    width: 8px;
    height: 15px;
    border-width: 0 3px 3px 0;
  }
  .cm-name {
    font-size: clamp(16px, 4.5vw, 20px);
  }
  .cm-item .collection-cover {
    height: 84px;
    width: auto;
  }
  .cm-footer {
    position: static;
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 16px;
  }
  .cm-newlabel,
  .cm-newfield {
    position: static;
    transform: none;
  }
  /* relative so the "+" pseudo-elements stay anchored to the button */
  .cm-add {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
  }
  .cm-newlabel {
    font-size: 18px;
  }
  .cm-newfield {
    flex: 1 1 160px;
    width: auto;
    height: 48px;
  }
  .cm-input {
    padding: 0 14px;
    border-radius: 12px;
    font-size: 16px;
  }
  .cm-add {
    width: 44px;
    height: 44px;
  }
  .cm-add:active {
    transform: scale(0.92);
  }
  .cm-add::before {
    width: 18px;
    height: 2.5px;
  }
  .cm-add::after {
    width: 2.5px;
    height: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cm-overlay,
  .cm-panel {
    transition: none;
  }
}

/* the sticky mobile topbar (z-index 1100) sits above this overlay, so drop the
   modal below it on ≤1024px. */
@media (max-width: 1024px) {
  .cm-overlay {
    align-items: flex-start;
    padding-top: 76px;
  }
  .cm-panel {
    max-height: calc(100dvh - 100px);
  }
}
