/*
  The new-space form as a title-bar card, after the design's New-space dialog with Blank chosen.
  Colours and controls are design.css's (`--ds-*`, `.ds-*`); the form carries `ds` itself.

  Rules start `atomics-new-space .new-space …` so they outrank design.css's `[ds] button` reset.
*/

atomics-new-space {
  display: block;
  width: 100%;
}

atomics-new-space .new-space {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--ds-r-dialog);
  background: var(--ds-panel);
  color: var(--ds-ink);
  box-shadow: 0 0 0 1px var(--ds-line), 0 24px 60px rgba(0, 0, 0, 0.12);
}

/* The bar's title is a heading for the page, so it keeps the bar's small centred label. */
atomics-new-space .new-space-bar h1 {
  font-size: 13px;
}

atomics-new-space .new-space-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: visible;
}

/* ------------------------------------------------------------------ sources */

atomics-new-space .new-space-split {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

atomics-new-space .new-space-split > .new-space-body {
  flex: 1 1 auto;
  min-width: 0;
}

/* In the dialog the body scrolls between the bar and the foot; on the page it grows with the page. */
atomics-new-space[railed] .new-space-body {
  overflow: auto;
}

atomics-new-space .new-space-rail {
  display: flex;
  flex: 0 0 200px;
  flex-direction: column;
  gap: 2px;
  box-sizing: border-box;
  padding: 12px;
  border-right: 1px solid var(--ds-line);
  background: var(--ds-panel2);
}

atomics-new-space .new-space-rail [source] {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--ds-ink);
  font-size: 13.5px;
  text-align: left;
}

atomics-new-space .new-space-rail [source]:hover {
  background: var(--ds-fill);
}

atomics-new-space .new-space-rail [source] small {
  font-size: 12px;
  opacity: 0.75;
}

atomics-new-space .new-space-rail [source][aria-selected='true'] {
  background: var(--ds-accent);
  color: var(--ds-on-accent);
}

atomics-new-space .new-space-starter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px 12px;
}

/*
  Beside the rail the fields are narrower than on the page, so Keep it gets the wider half and its
  options drop their icons, as the design draws them.
*/
atomics-new-space[railed] .new-space-fields {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
}

atomics-new-space[railed] .ds-keep-it-modes > button {
  min-width: 0;
  padding: 0 8px;
}

atomics-new-space[railed] .ds-keep-it-modes > button .ds-i {
  display: none;
}

atomics-new-space .new-space-starter {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 6px;
  min-width: 0;
  padding: 0;
  color: var(--ds-ink);
  text-align: left;
}

atomics-new-space .new-space-starter-board {
  display: block;
  aspect-ratio: 16 / 10;
  margin-bottom: 2px;
  border-radius: 10px;
  transition: box-shadow var(--ds-fast) ease;
}

atomics-new-space .new-space-starter:hover .new-space-starter-board {
  box-shadow: inset 0 0 0 1px var(--ds-line-strong);
}

atomics-new-space .new-space-starter[aria-checked='true'] .new-space-starter-board {
  box-shadow: 0 0 0 2px var(--ds-accent);
}

atomics-new-space .new-space-starter b {
  font-size: 13.5px;
  font-weight: 600;
}

atomics-new-space .new-space-starter small {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ds-mute);
  font-size: 12px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

atomics-new-space .new-space-starter-all {
  display: inline-block;
  margin-top: 12px;
  color: var(--ds-accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

atomics-new-space .new-space-file {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  box-sizing: border-box;
  padding: 24px 20px;
  border: 1.5px dashed var(--ds-line-strong);
  border-radius: 12px;
  color: var(--ds-mute);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}

atomics-new-space .new-space-file:hover,
atomics-new-space .new-space-file:focus-within {
  border-color: var(--ds-accent);
}

atomics-new-space .new-space-file[chosen] {
  border-style: solid;
  border-color: var(--ds-accent);
  background: var(--ds-info-soft);
}

atomics-new-space .new-space-file .ds-i {
  width: 28px;
  height: 28px;
}

atomics-new-space .new-space-file strong {
  color: var(--ds-ink);
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Out of sight but still the label's control, so the whole panel opens the chooser. */
atomics-new-space .new-space-file input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

atomics-new-space :is(.new-space-file-note, .new-space-status) {
  margin: -6px 0 0;
  color: var(--ds-mute);
  font-size: 13px;
  line-height: 1.5;
}

/* `[ds] [hidden]` already says this; said here too, since these rules give each a display. */
atomics-new-space :is([panel], .new-space-rail, [source])[hidden] {
  display: none;
}

/* Hosted in a `<dialog class="ds-dialog">`, the dialog is the card. */
dialog > atomics-new-space {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

dialog > atomics-new-space .new-space {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 0;
  box-shadow: none;
}

atomics-new-space .new-space-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 7;
  padding: 16px;
  border-radius: 12px;
  background-color: var(--ds-board);
  background-image: radial-gradient(var(--ds-board-dot) 1px, transparent 1.4px);
  background-size: 18px 18px;
  box-shadow: inset 0 0 0 1px var(--ds-line);
  color: var(--ds-mute);
  font-size: 13.5px;
  text-align: center;
}

atomics-new-space .new-space-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 16px 20px;
  align-items: start;
}

atomics-new-space .new-space-name {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

atomics-new-space .new-space-label {
  color: var(--ds-mute);
  font-size: 12.5px;
  font-weight: 600;
}

atomics-new-space .new-space-name .ds-search {
  width: 100%;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------- advanced */

atomics-new-space .new-space-advanced {
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--ds-line);
}

atomics-new-space .new-space-advanced > summary {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  list-style: none;
  cursor: pointer;
}

atomics-new-space .new-space-advanced > summary::-webkit-details-marker {
  display: none;
}

atomics-new-space .new-space-advanced > summary .ds-i {
  flex: 0 0 auto;
  margin-top: 2px;
  transform: rotate(-90deg);
  transition: transform var(--ds-fast) ease;
}

atomics-new-space .new-space-advanced[open] > summary .ds-i {
  transform: none;
}

atomics-new-space .new-space-advanced > summary b {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

atomics-new-space .new-space-advanced > summary small {
  display: block;
  margin-top: 2px;
  color: var(--ds-mute);
  font-size: 12.5px;
  line-height: 1.45;
}

atomics-new-space .space-creation-advanced {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 14px 16px;
}

atomics-new-space .space-creation-warning {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--ds-warn-soft);
  color: var(--ds-warn);
  font-size: 13px;
  line-height: 1.5;
}

atomics-new-space .space-creation-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13.5px;
}

atomics-new-space .space-creation-field label {
  color: var(--ds-mute);
  font-size: 12.5px;
  font-weight: 600;
}

atomics-new-space .space-creation-field small {
  color: var(--ds-mute);
  font-size: 12.5px;
  line-height: 1.45;
}

atomics-new-space .space-creation-field small:empty {
  display: none;
}

atomics-new-space .space-creation-field select {
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: var(--ds-fill);
  color: var(--ds-ink);
  font: inherit;
  font-size: 14px;
}

atomics-new-space .space-creation-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

atomics-new-space .space-creation-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 99px;
  box-shadow: inset 0 0 0 1px var(--ds-line);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  cursor: pointer;
}

atomics-new-space .space-creation-tag[checked] {
  background: var(--ds-ink);
  color: var(--ds-panel);
  box-shadow: none;
}

atomics-new-space .space-creation-tag input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

atomics-new-space .space-creation-grades {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

atomics-new-space .space-creation-grades > span {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

atomics-new-space .space-creation-warnings {
  margin: 0;
  padding-left: 18px;
  color: var(--ds-warn);
  font-size: 13px;
  line-height: 1.5;
}

atomics-new-space .space-creation-warnings:empty {
  display: none;
}

/* ------------------------------------------------------------- error, foot */

atomics-new-space .new-space-error {
  margin: 0;
  color: var(--ds-danger);
  font-size: 13.5px;
  font-weight: 600;
}

atomics-new-space .new-space-foot {
  align-items: center;
}

atomics-new-space .new-space-hint {
  flex: 1 1 auto;
  color: var(--ds-mute);
  font-size: 12.5px;
}

atomics-new-space .new-space-hint kbd {
  padding: 1px 5px;
  border: 1px solid var(--ds-line);
  border-radius: 4px;
  font-family: inherit;
}

atomics-new-space .space-creation-btn[working] {
  cursor: progress;
}

@media (max-width: 720px) {
  atomics-new-space .new-space-hint {
    display: none;
  }

  /* The rail turns into a row of three along the top. */
  atomics-new-space .new-space-split {
    flex-direction: column;
  }

  atomics-new-space .new-space-rail:not([hidden]) {
    flex: 0 0 auto;
    flex-direction: row;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--ds-line);
  }

  atomics-new-space .new-space-rail [source] {
    flex: 1 1 0;
    align-items: center;
    min-width: 0;
    padding: 8px 4px;
    font-size: 13px;
    text-align: center;
    white-space: nowrap;
  }

  atomics-new-space .new-space-rail [source] small {
    display: none;
  }

  atomics-new-space .new-space-starter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  atomics-new-space[railed] .new-space-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  atomics-new-space .space-creation-grades {
    grid-template-columns: 1fr;
  }
}
