.connection-setup, .connection-detail {
  max-width: 48rem;
}

.connection-detail h1 { overflow-wrap: anywhere; }

.connection-heading {
  margin-block: 1.5rem 2rem;

  h1 { margin-bottom: 0.65rem; }
  p { color: var(--muted); max-width: 42rem; line-height: 1.65; }
}

.connection-form {
  fieldset { border: 0; padding: 0; margin: 0 0 2rem; min-width: 0; }
  legend { padding: 0; margin-bottom: 1.1rem; font-size: 1.1rem; font-weight: 600; }
  label { display: block; margin-bottom: 0.45rem; font-weight: 500; }
  .optional { color: var(--muted); margin-left: 0.4rem; font-weight: 400; font-size: 0.8em; }

  input[type="text"], input[type="url"], input[type="password"], textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--line);
    border-radius: 0.35rem;
    padding: 0.75rem 0.85rem;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: max(1rem, 16px);
    line-height: 1.5;
  }
  textarea { min-height: 7rem; resize: vertical; }
  input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
  input[readonly] { color: var(--muted); background: var(--wash); }
}

.connection-field { margin-bottom: 1.25rem; }
.connection-field:last-child { margin-bottom: 0; }
.field-help { color: var(--muted); font-size: 0.88rem; line-height: 1.6; margin: 0.5rem 0 0; }
.connection-explanation { color: var(--muted); font-size: 0.95rem; line-height: 1.65; margin: 1rem 0; }
.connection-advanced {
  margin-top: 1.25rem;
  summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
  &[open] summary { margin-bottom: 1rem; }
}

.connection-summary {
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--wash);
  margin-bottom: 1.75rem;
  h2 { margin: 0 0 0.65rem; font-size: 1.1rem; }
  p { color: var(--muted); font-size: 0.93rem; line-height: 1.65; margin: 0 0 1rem; }
}
.connection-errors, .connection-summary .connection-errors { color: var(--bad); font-size: 0.95rem; line-height: 1.6; }

.connection-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem 1.25rem;
  font-size: 0.95rem;
  form { margin: 0; }
  .button-link { padding: 0; }
}
.connection-button, .connection-form input[type="submit"] {
  display: inline-block;
  border: 1px solid var(--ink);
  border-radius: 0.35rem;
  padding: 0.7rem 1.1rem;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  text-decoration: none;
  &:hover { opacity: 0.85; color: var(--paper); text-decoration: none; }
}

.connection-invite {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 1.5rem;
  margin-block: 2rem;
  h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
  p { margin-block: 0.4rem 0; }
  table, .empty { flex-basis: 100%; }
  td form { display: inline; }
}
.connections-intro { margin-top: 1.2rem; max-width: var(--measure); }
.connection-summary dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.6rem 1.25rem;
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
  dt { color: var(--muted); }
  dd { margin: 0; overflow-wrap: anywhere; }
}
.connection-catalogue > header p { color: var(--muted); font-size: 0.95rem; line-height: 1.65; }
.tool-group {
  position: relative;
  margin-block: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sheet);
  > details > summary {
    display: flex;
    align-items: center;
    min-height: 3rem;
    padding: 0.5rem 8.5rem 0.5rem 1rem;
    cursor: pointer;
    list-style: none;
    &::-webkit-details-marker { display: none; }
    &::before { content: "›"; margin-right: 0.6rem; color: var(--muted); transition: rotate 0.15s; }
  }
  > details[open] > summary::before { rotate: 90deg; }
  h3 { margin: 0; font-size: var(--text-base); }
  .count { color: var(--muted); font-weight: normal; margin-left: 0.3rem; }
  /* The tools set apart from the group's usual setting, counted on its header and listed first. */
  h3 .apart {
    font-size: 0.85rem;
    font-weight: normal;
    margin-left: 0.6rem;
    &.disabled { color: var(--bad); }
    &.assistants { color: var(--out); }
    &.agents { color: var(--good); }
  }
  /* The group's own setting sits on its header row, outside the summary that toggles it. */
  > .tool-access { position: absolute; top: 0.5rem; right: 1rem; z-index: 1; }
}
.connection-tools {
  list-style: none;
  padding: 0;
  margin: 0;
  li {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid var(--line);
    padding: 0.6rem 1rem;
  }
  li.apart { background: var(--warn-wash); }
  li > details { flex: 1; min-width: 0; padding-block: 0.3rem; }
  summary { cursor: pointer; overflow-wrap: anywhere; }
  code { font-size: var(--text-md); }
  p { color: var(--muted); font-size: 0.95rem; line-height: 1.6; white-space: pre-wrap; }
  details details summary { color: var(--muted); font-size: 0.85rem; }
  pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.8rem; }
}
.tool-access {
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--wash);
  button {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 1.75rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    &:hover { color: var(--ink); background: var(--sheet); }
    &[aria-pressed="true"] { background: var(--sheet); box-shadow: 0 0 0 1px var(--line); }
    &.disabled[aria-pressed="true"] { color: var(--bad); }
    &.assistants[aria-pressed="true"] { color: var(--out); }
    &.agents[aria-pressed="true"] { color: var(--good); }
  }
  svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
}
span.tool-access { align-items: center; gap: 0.4rem; padding: 0.25rem 0.5rem; font-size: var(--text-sm); color: var(--muted); }
.connection-call-result pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.85rem; }

@media (max-width: 40rem) {
  .connection-summary, .connection-invite { padding: 1rem; }
  .connection-summary dl { grid-template-columns: 1fr; gap: 0.25rem; }
  .connection-summary dd { margin-bottom: 0.5rem; }
}
