/* Collection creation: scoped so legacy modal forms remain unchanged. */
#collectionDialog.collection-create-modal {
  width: min(520px, calc(100vw - 32px));
  max-width: 520px;
  max-height: min(720px, calc(100dvh - 32px));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 28px 74px rgba(15, 23, 42, .22);
}

#collectionDialog.collection-create-modal::backdrop {
  background: rgba(15, 23, 42, .46);
  backdrop-filter: blur(5px) saturate(.9);
  -webkit-backdrop-filter: blur(5px) saturate(.9);
}

#collectionDialog.collection-create-modal form {
  display: grid;
  height: min(660px, calc(100dvh - 32px));
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.collection-create-head,
.collection-create-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
}

.collection-create-head { align-items: flex-start; }
.collection-create-head h2 { margin: 0; font-size: 1.3rem; letter-spacing: -.02em; }
.collection-create-head p { margin: 5px 0 0; color: var(--muted); font-size: .88rem; line-height: 1.42; }
.collection-create-close { flex: 0 0 auto; width: 40px; height: 40px; min-height: 40px; border-color: color-mix(in srgb, var(--primary) 18%, var(--line)); color: var(--ink); background: color-mix(in srgb, var(--surface) 92%, var(--bg)); }

.collection-create-body {
  display: grid;
  gap: 17px;
  min-height: 0;
  padding: 0 24px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.collection-create-field { display: grid; gap: 8px; }
.collection-create-field > span:first-child { color: var(--ink); font-size: .88rem; font-weight: 820; }
.collection-create-field > span:first-child b { color: #e4535d; font-size: 1rem; }
.collection-create-field > span:first-child em { margin-left: 4px; color: var(--muted); font-size: .78rem; font-style: normal; font-weight: 650; }

.collection-input-shell { position: relative; display: grid; align-items: center; }
.collection-input-shell svg { position: absolute; left: 14px; width: 20px; height: 20px; color: var(--primary); pointer-events: none; }
.collection-create-field input[type="text"],
.collection-create-field textarea {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: 0;
  background: color-mix(in srgb, var(--surface) 87%, var(--bg));
  color: var(--ink);
  font: inherit;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.collection-create-field input[type="text"] { min-height: 50px; padding: 0 14px 0 45px; }
.collection-create-field textarea { min-height: 102px; max-height: 160px; padding: 12px 14px; line-height: 1.45; resize: vertical; }
.collection-create-field input[type="text"]::placeholder,
.collection-create-field textarea::placeholder { color: color-mix(in srgb, var(--muted) 72%, transparent); }
.collection-create-field input[type="text"]:focus,
.collection-create-field textarea:focus { border-color: #3b82f6; background: var(--surface); box-shadow: 0 0 0 3px rgba(59, 130, 246, .13); }
.collection-create-field input[aria-invalid="true"] { border-color: #e4535d; box-shadow: 0 0 0 3px rgba(228, 83, 93, .12); }
.collection-field-error { color: #c73e49; font-size: .76rem; font-weight: 700; }

.collection-color-options { display: flex; flex-wrap: wrap; gap: 11px; align-items: center; padding: 11px 12px; border: 1px solid color-mix(in srgb, var(--line) 78%, transparent); border-radius: 14px; background: color-mix(in srgb, var(--surface) 88%, var(--bg)); }
.collection-color-swatch,
.collection-color-custom { display: grid; width: 31px; height: 31px; place-items: center; padding: 0; border: 2px solid transparent; border-radius: 999px; color: #fff; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
.collection-color-swatch:hover,
.collection-color-custom:hover { transform: translateY(-1px); }
.collection-color-swatch svg { display: none; width: 17px; height: 17px; }
.collection-color-swatch[aria-pressed="true"] { border-color: var(--surface); box-shadow: 0 0 0 2px var(--primary); }
.collection-color-swatch[aria-pressed="true"] svg { display: block; }
.swatch-teal { background: #176b87; }.swatch-blue { background: #3577e8; }.swatch-purple { background: #8354cf; }.swatch-rose { background: #e74f69; }.swatch-orange { background: #ec7a32; }.swatch-green { background: #42a87d; }
.collection-color-custom { margin-left: 2px; border-color: var(--line); background: var(--surface); color: var(--ink); font-size: 1.55rem; font-weight: 350; line-height: 1; }
.collection-color-custom[aria-pressed="true"] { border-color: var(--surface); box-shadow: 0 0 0 2px var(--primary); }
.collection-native-color { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.collection-color-preview { display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 0 2px; color: var(--muted); font-size: .75rem; font-weight: 650; }
.collection-color-preview > i { width: 22px; height: 22px; flex: 0 0 auto; border-radius: 8px; background: var(--collection-preview-color, #176b87); box-shadow: inset 0 0 0 1px rgba(255,255,255,.34), 0 3px 9px color-mix(in srgb, var(--collection-preview-color, #176b87) 27%, transparent); }

.collection-icon-options {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 88%, var(--bg));
}
.collection-icon-choice {
  display: grid;
  min-width: 0;
  min-height: 54px;
  place-items: center;
  gap: 3px;
  padding: 7px 4px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, color .16s ease, transform .16s ease;
}
.collection-icon-choice:hover { transform: translateY(-1px); color: var(--collection-icon-color, #176b87); background: color-mix(in srgb, var(--collection-icon-color, #176b87) 7%, var(--surface)); }
.collection-icon-choice[aria-pressed="true"] { border-color: color-mix(in srgb, var(--collection-icon-color, #176b87) 54%, var(--line)); background: color-mix(in srgb, var(--collection-icon-color, #176b87) 13%, var(--surface)); color: var(--collection-icon-color, #176b87); box-shadow: 0 5px 13px color-mix(in srgb, var(--collection-icon-color, #176b87) 12%, transparent); }
.collection-icon-choice span { display: block; width: 100%; overflow: hidden; font-size: .63rem; font-weight: 740; line-height: 1.2; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.collection-custom-icon { display: block; border-radius: 5px; object-fit: contain; }

.collection-child-safe-card { position: relative; display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 9px; align-items: center; min-height: 52px; padding: 9px 11px; border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--line)); border-radius: 14px; background: color-mix(in srgb, var(--surface) 88%, var(--bg)); cursor: pointer; transition: border-color .16s ease, background .16s ease, box-shadow .16s ease; }
.collection-child-safe-card:has(input:checked) { border-color: rgba(45, 139, 101, .48); background: color-mix(in srgb, #e8f7ef 68%, var(--surface)); box-shadow: 0 5px 14px rgba(45, 139, 101, .09); }
.collection-child-safe-icon { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; color: #2d8b65; background: rgba(66, 168, 125, .12); }
.collection-child-safe-icon svg { width: 18px; height: 18px; }
.collection-child-safe-card strong { display: block; color: var(--ink); font-size: .82rem; }
.collection-child-safe-card input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.collection-switch { position: relative; width: 42px; height: 24px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 28%, var(--surface)); transition: background .16s ease; }
.collection-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(15, 23, 42, .24); transition: transform .16s ease; }
.collection-child-safe-card input:checked + .collection-switch { background: #2d8b65; }.collection-child-safe-card input:checked + .collection-switch::after { transform: translateX(18px); }
.collection-child-safe-card input:focus-visible + .collection-switch { outline: 3px solid rgba(59, 130, 246, .23); outline-offset: 2px; }

.collection-create-footer { padding-top: 15px; padding-bottom: 18px; border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent); background: color-mix(in srgb, var(--surface) 94%, var(--bg)); }
.collection-create-footer .ghost-btn,
.collection-create-footer .primary-action { min-height: 44px; padding: 0 16px; border-radius: 12px; }
.collection-create-footer .primary-action { gap: 8px; background: linear-gradient(135deg, #3177ee, #4fb4ed); box-shadow: 0 10px 22px rgba(49, 119, 238, .2); }
.collection-create-footer .primary-action > span { font-size: 1.25rem; font-weight: 400; line-height: 1; }

body.dark #collectionDialog.collection-create-modal { border-color: var(--line); background: var(--surface); box-shadow: 0 30px 78px rgba(0, 0, 0, .54); }
body.dark .collection-create-close,
body.dark .collection-create-field input[type="text"],
body.dark .collection-create-field textarea,
body.dark .collection-color-options,
body.dark .collection-icon-options,
body.dark .collection-color-custom,
body.dark .collection-child-safe-card { border-color: var(--line); background: color-mix(in srgb, var(--bg) 74%, var(--surface)); color: var(--ink); }
body.dark .collection-child-safe-card:has(input:checked) { border-color: rgba(73, 168, 121, .62); background: rgba(22, 131, 77, .16); }
body.dark .collection-create-footer { border-color: var(--line); background: color-mix(in srgb, var(--surface) 94%, #000); }

@media (max-width: 560px) {
  #collectionDialog.collection-create-modal {
    position: fixed !important;
    inset: calc(8px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom)) !important;
    box-sizing: border-box !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    overflow: hidden !important;
    border-radius: 20px !important;
  }
  #collectionDialog.collection-create-modal form {
    display: flex !important;
    flex-direction: column !important;
    width: 100%;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
  }
  .collection-create-head { padding: 18px 20px 14px; }.collection-create-head p { display: none; }
  .collection-create-head,.collection-create-footer { flex: 0 0 auto; }
  .collection-create-body {
    flex: 1 1 0 !important;
    display: grid !important;
    gap: 15px;
    min-height: 0 !important;
    padding: 0 20px 28px;
    overflow-y: scroll !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    scroll-padding-bottom: 28px;
  }
  .collection-create-body > :last-child { margin-bottom: 6px; }
  .collection-create-footer { position: relative; z-index: 3; gap: 10px; padding: 13px 20px calc(13px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 24px rgba(15,23,42,.07); }
  .collection-create-footer .ghost-btn,
  .collection-create-footer .primary-action { flex: 1 1 0; justify-content: center; min-width: 0; padding: 0 10px; }
  .collection-color-options { gap: 9px; }.collection-color-swatch,.collection-color-custom { width: 29px; height: 29px; }
  .collection-icon-options { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding: 8px; }
  .collection-icon-choice { min-height: 50px; }
}

@media (max-width: 360px) {
  .collection-icon-options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .collection-create-footer { display: grid; grid-template-columns: 1fr; }.collection-create-footer .ghost-btn,.collection-create-footer .primary-action { width: 100%; }
}
.collection-child-safe-card.plan-feature-locked{grid-template-columns:30px minmax(0,1fr) auto auto;cursor:not-allowed}.collection-child-safe-card.plan-feature-locked::after{position:static;grid-column:3;grid-row:1;min-height:0;margin:0;padding:3px 7px;border:1px solid rgba(217,154,18,.34);border-radius:999px;background:#fff8e7;color:#8b650f;content:"Gold";font-size:.65rem;font-weight:900;line-height:1.2}.collection-child-safe-card.plan-feature-locked .collection-switch{grid-column:4;grid-row:1}.collection-child-safe-card.plan-feature-locked input,.collection-child-safe-card.plan-feature-locked .collection-switch{pointer-events:none}
