/**
 * Sharing a space, in the shape of Keith's ⌘K design (2026-10-06): a popover rather than a dimmed
 * dialog, opened from the space's app menu and held under its pill, the people with access at the
 * top, and every change applied as it is made.
 *
 * Its colours are design.css's `--ds-*` tokens, the same as the command menu's, each falling back to
 * the space's own for a page that has not loaded design.css. Still a `<dialog>` opened modally, for
 * the focus trap and Escape; the backdrop is clear and closes it, the way a popover does.
 */
.atomics-space-sharing {
  --sh-panel: var(--ds-panel, var(--background, #ffffff));
  --sh-ink: var(--ds-ink, var(--text, #1d1d1f));
  --sh-mute: var(--ds-mute, color-mix(in srgb, var(--text, #1d1d1f) 58%, var(--background, #ffffff)));
  --sh-line: var(--ds-line, color-mix(in srgb, var(--text, #1d1d1f) 10%, transparent));
  --sh-fill: var(--ds-fill, color-mix(in srgb, var(--text, #1d1d1f) 9%, var(--background, #ffffff)));
  --sh-accent: var(--ds-accent, #2f6bff);
  --sh-danger: #d93b30;

  position: fixed;
  inset: 0;
  z-index: 7;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  color: var(--sh-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.atomics-space-sharing:not([open]) {
  display: none;
}

.atomics-space-sharing::backdrop {
  background: transparent;
}

.atomics-space-sharing-background {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.16);
}

@keyframes atomics-space-sharing-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.atomics-space-sharing-container {
  position: relative;
  width: 440px;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 84px);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
  border-radius: 16px;
  background: var(--sh-panel);
  color: var(--sh-ink);
  font-family: var(--ds-font, inherit);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  box-shadow:
    0 0 0 1px var(--sh-line),
    0 30px 70px -20px rgb(0 0 0 / 0.4);
  display: flex;
  flex-direction: column;
  animation: atomics-space-sharing-in 0.16s ease;
}

@media (prefers-reduced-motion: reduce) {
  .atomics-space-sharing-container {
    animation: none;
  }
}

/**
 * Inside a space, it hangs under the pill the way the design draws it, and the canvas stays in view
 * behind it. On the Spaces library it is opened from a card anywhere on the page, so it stays in the
 * middle with the page dimmed behind.
 */
atomics-space-view > atomics-space-sharing .atomics-space-sharing-background {
  background: transparent;
}

atomics-space-view > atomics-space-sharing .atomics-space-sharing {
  align-items: flex-start;
  justify-content: flex-start;
}

atomics-space-view > atomics-space-sharing .atomics-space-sharing-container {
  position: absolute;
  top: 68px;
  left: 16px;
}

.atomics-space-sharing [hidden] {
  display: none !important;
}

.atomics-space-sharing button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.atomics-space-sharing button:disabled {
  cursor: default;
  opacity: 0.5;
}

.atomics-space-sharing :focus-visible {
  outline: 2px solid var(--sh-accent);
  outline-offset: 2px;
}

.atomics-space-sharing-container header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px 20px;
}

.atomics-space-sharing-container h2 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.atomics-space-sharing [option='close'] {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sh-mute);
  display: flex;
  align-items: center;
  justify-content: center;
}

.atomics-space-sharing [option='close'] svg {
  width: 15px;
  height: 15px;
}

.atomics-space-sharing [option='close']:hover {
  background: var(--sh-fill);
}

.atomics-space-sharing [prop='offline'],
.atomics-space-sharing [prop='local'],
.atomics-space-sharing [prop='visitor'] {
  margin: 0 16px 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--sh-fill);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--sh-mute);
}

/* The invite row: a field holding the role it will give, then the button. */
.atomics-space-sharing [prop='invite'] {
  display: flex;
  gap: 8px;
  padding: 0 16px 14px;
}

.atomics-space-sharing [prop='field'] {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 4px 0 12px;
  box-sizing: border-box;
  border-radius: 10px;
  box-shadow: inset 0 0 0 1.5px var(--sh-line);
}

.atomics-space-sharing [prop='field']:focus-within {
  box-shadow: inset 0 0 0 1.5px var(--sh-accent);
}

.atomics-space-sharing [prop='field'] input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--sh-ink);
  font: inherit;
  font-size: 14px;
}

.atomics-space-sharing [prop='field'] input::placeholder {
  color: var(--sh-mute);
  opacity: 1;
}

.atomics-space-sharing [prop='invite-role'] {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: var(--sh-fill);
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.atomics-space-sharing [prop='invite-role'] svg,
.atomics-space-sharing [role-button] svg {
  width: 11px;
  height: 11px;
}

.atomics-space-sharing [option='add'] {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--sh-fill);
  color: var(--sh-mute);
  font-size: 13.5px;
  font-weight: 600;
}

.atomics-space-sharing [prop='invite'][ready] [option='add'] {
  background: var(--sh-accent);
  color: #ffffff;
}

.atomics-space-sharing h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--sh-mute);
}

/* People with access. */
.atomics-space-sharing [grouping='people'] {
  display: flex;
  flex-direction: column;
  padding: 0 8px 8px;
}

.atomics-space-sharing [grouping='people'][empty] {
  display: none;
}

.atomics-space-sharing [grouping='people'] h3 {
  padding: 4px 12px 6px;
}

.atomics-space-sharing [prop='people'] {
  margin: 0;
  padding: 0;
  list-style: none;
}

.atomics-space-sharing [person] {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 0 8px 0 12px;
  border-radius: 10px;
}

.atomics-space-sharing [face] {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: var(--face, var(--sh-accent));
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.atomics-space-sharing [person] [copy] {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.atomics-space-sharing [person] [name] {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.atomics-space-sharing [person] [handle] {
  font-size: 12px;
  color: var(--sh-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.atomics-space-sharing [person] [tag] {
  flex: 0 0 auto;
  padding-right: 8px;
  font-size: 13px;
  color: var(--sh-mute);
}

.atomics-space-sharing [role-button] {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.atomics-space-sharing [role-button]:hover,
.atomics-space-sharing [role-button][aria-expanded='true'] {
  background: var(--sh-fill);
}

.atomics-space-sharing [menu] {
  position: absolute;
  right: 8px;
  top: 44px;
  z-index: 3;
  width: 210px;
  padding: 5px;
  box-sizing: border-box;
  border-radius: 12px;
  background: var(--sh-panel);
  box-shadow:
    0 0 0 1px var(--sh-line),
    0 18px 40px -12px rgb(0 0 0 / 0.35);
}

.atomics-space-sharing [menu] button {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.atomics-space-sharing [menu] button:hover {
  background: var(--sh-fill);
}

.atomics-space-sharing [menu] button[danger] {
  color: var(--sh-danger);
}

.atomics-space-sharing [menu] [tick] {
  width: 14px;
  flex: 0 0 14px;
  font-size: 13px;
  color: var(--sh-accent);
}

.atomics-space-sharing [menu] [words] {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.atomics-space-sharing [menu] [label] {
  font-size: 13.5px;
  font-weight: 600;
}

.atomics-space-sharing [menu] [sub] {
  font-size: 11.5px;
  color: var(--sh-mute);
}

/* Who can open it, and the link: ruled sections under the people. */
.atomics-space-sharing [grouping='visibility'],
.atomics-space-sharing [grouping='link'] {
  margin: 0 16px;
  padding: 14px 0;
  border-top: 1px solid var(--sh-line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.atomics-space-sharing [grouping='choices'] {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--sh-fill);
}

.atomics-space-sharing [grouping='choices'] button {
  flex: 1 1 0;
  min-width: 0;
  height: 32px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sh-mute);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.atomics-space-sharing [grouping='choices'] button[aria-pressed='true'] {
  background: var(--sh-panel);
  color: var(--sh-ink);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}

.atomics-space-sharing [grouping='choices'] button:disabled {
  opacity: 1;
}

.atomics-space-sharing [prop='note'],
.atomics-space-sharing [prop='reach'] {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--sh-mute);
  text-wrap: pretty;
}

.atomics-space-sharing [prop='reach'] {
  font-size: 12.5px;
}

.atomics-space-sharing [prop='address'] {
  display: flex;
  gap: 8px;
}

.atomics-space-sharing [prop='href'] {
  flex: 1 1 auto;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  box-sizing: border-box;
  border: 0;
  border-radius: 9px;
  background: var(--sh-fill);
  color: var(--sh-ink);
  font: inherit;
  font-size: 13.5px;
  text-overflow: ellipsis;
}

.atomics-space-sharing [option='copy'] {
  flex: 0 0 auto;
  min-width: 84px;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: var(--sh-ink);
  color: var(--sh-panel);
  font-size: 13px;
  font-weight: 600;
}

/* The two disclosures: the code and the name, each a row that opens in place. */
.atomics-space-sharing details {
  margin: 0 16px;
  border-top: 1px solid var(--sh-line);
}

.atomics-space-sharing summary {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.atomics-space-sharing summary::-webkit-details-marker {
  display: none;
}

.atomics-space-sharing summary > span:first-of-type {
  flex: 1 1 auto;
}

.atomics-space-sharing summary [glyph] {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.atomics-space-sharing summary [caret] {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  color: var(--sh-mute);
  transition: transform 0.2s;
}

.atomics-space-sharing details[open] summary [caret] {
  transform: rotate(90deg);
}

.atomics-space-sharing [prop='name-state'] {
  max-width: 45%;
  margin-right: 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--sh-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.atomics-space-sharing [prop='code'] {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 0 0 16px;
}

.atomics-space-sharing [prop='qr'] {
  width: 120px;
  height: 120px;
  flex: 0 0 120px;
  padding: 8px;
  box-sizing: border-box;
  border-radius: 12px;
  background: #ffffff;
  color: #1d1d1f;
  box-shadow: 0 0 0 1px var(--sh-line);
}

.atomics-space-sharing [prop='qr'] svg {
  display: block;
  width: 100%;
  height: 100%;
}

.atomics-space-sharing [prop='code-rule'] {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--sh-mute);
  text-wrap: pretty;
}

.atomics-space-sharing [prop='naming'] {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 0 16px;
}

.atomics-space-sharing [prop='claim'] {
  display: flex;
  gap: 8px;
}

.atomics-space-sharing [prop='claim'] [prop='field'] {
  height: 38px;
  font-size: 13.5px;
}

.atomics-space-sharing [prop='claim'] [prefix] {
  color: var(--sh-mute);
  white-space: nowrap;
}

.atomics-space-sharing [prop='claim'] input {
  font-size: 13.5px;
}

/**
 * Grey until the registry has said the name is free, and blue once it has, as the design draws it.
 * Still pressable while grey: a check that could not be made is not a refusal, and the server
 * decides either way.
 */
.atomics-space-sharing [option='claim'] {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: var(--sh-fill);
  color: var(--sh-mute);
  font-size: 13px;
  font-weight: 600;
}

.atomics-space-sharing [prop='claim'][ready] [option='claim'] {
  background: var(--sh-accent);
  color: #ffffff;
}

.atomics-space-sharing [prop='availability'] {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--sh-mute);
}

.atomics-space-sharing [prop='availability']:empty {
  display: none;
}

.atomics-space-sharing [prop='availability'][state='available'] {
  color: #3f9d5b;
}

.atomics-space-sharing [prop='availability'][state='unavailable'] {
  color: var(--sh-danger);
}

.atomics-space-sharing [prop='plan'] {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--sh-mute);
}

.atomics-space-sharing [prop='plan'] a {
  color: var(--sh-accent);
  font-weight: 600;
}

.atomics-space-sharing [prop='held'] {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
}

.atomics-space-sharing [prop='held'] span {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.atomics-space-sharing [prop='held'] b {
  font-weight: 650;
}

.atomics-space-sharing [option='release'] {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sh-danger);
  font-size: 13px;
  font-weight: 600;
}

.atomics-space-sharing [option='release']:hover {
  background: rgb(226 69 58 / 0.1);
}

.atomics-space-sharing [prop='error'] {
  margin: 0 16px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--sh-danger);
}

.atomics-space-sharing [prop='error']:empty {
  display: none;
}

.atomics-space-sharing [prop='error']:not(:empty) {
  padding: 0 0 12px;
}

/* Pinned to the bottom of the card, so Done stays in reach with both disclosures open. */
.atomics-space-sharing footer {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--sh-line);
  background: var(--sh-panel);
}

.atomics-space-sharing [prop='status'] {
  flex: 1 1 auto;
  margin: 0;
  font-size: 12.5px;
  color: var(--sh-mute);
}

.atomics-space-sharing [prop='status'][phase='failed'] {
  color: var(--sh-danger);
}

.atomics-space-sharing [option='done'] {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 18px;
  border: 0;
  border-radius: 9px;
  background: var(--sh-accent);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
}

/* A phone: the full width, just under the pill, and the choices allowed to wrap their words. */
@media (max-width: 720px) {
  atomics-space-view > atomics-space-sharing .atomics-space-sharing-container {
    top: 64px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    max-height: calc(100% - 76px);
  }

  .atomics-space-sharing [grouping='choices'] button {
    height: auto;
    min-height: 32px;
    padding: 4px 6px;
    white-space: normal;
    line-height: 1.2;
  }
}
