/* ==================================================================
   Groups. 8.648.0.

   The directory, the creation form and the group page. Conditional,
   like technologies.css and community.css: three templates load it
   and nothing else does, so it stays out of the always-on bundle.

   Composition over invention. The cards are the `dir-card` family the
   Topics and Technologies directories already use, with the
   group-specific parts scoped under .groups-grid and .groups-list; the
   page heading is the shared .page-header from 8.647.0; buttons,
   notices and chips are the platform's own. What is genuinely new here
   is the cover-plus-mark treatment, the privacy chooser and the
   switches, because nothing in the product drew those before.
   ================================================================== */

.groups-page {
  padding-inline: var(--space-6);
  padding-block: var(--space-6) var(--space-10);
}

.groups-shell { max-width: var(--container-xl, 1280px); margin-inline: auto; }

.groups-main { min-width: 0; }

/* ---- Controls ---------------------------------------------------- */

.groups-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.groups-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 22rem;
  min-width: 0;
}

.groups-search__icon {
  position: absolute;
  inset-inline-start: var(--space-3);
  color: var(--color-text-muted);
  pointer-events: none;
}

.groups-search input {
  width: 100%;
  min-height: 44px;
  padding-block: 0;
  padding-inline: calc(var(--space-3) * 2 + 16px) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-white);
  font: inherit;
  color: var(--color-ink);
}

.groups-select select {
  min-height: 44px;
  padding-inline: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  font: inherit;
  color: var(--color-ink);
}

.groups-search input:focus-visible,
.groups-select select:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.groups-controls__go { flex: 0 0 auto; min-height: 44px; }

/* ---- Category chips ---------------------------------------------- */

.groups-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.groups-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding-inline: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-white);
  color: var(--color-ink);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.groups-chip:hover { border-color: var(--color-primary); color: var(--color-primary-text); }

.groups-chip.is-active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-white);
}

.groups-chip:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.groups-chip-more { position: relative; }

.groups-chip-more > summary { list-style: none; }
.groups-chip-more > summary::-webkit-details-marker { display: none; }

.groups-chip-more__panel {
  position: absolute;
  inset-inline-start: 0;
  top: calc(100% + var(--space-1));
  z-index: 20;
  min-width: 15rem;
  max-height: 18rem;
  overflow-y: auto;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  box-shadow: var(--shadow-md);
}

/* Closed, the panel is not in the layout at all. A panel that is
   merely transparent still takes its width, which is how a hidden
   menu ends up widening the page by a few hundred pixels. */
.groups-chip-more:not([open]) .groups-chip-more__panel { display: none; }

.groups-chip-more__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 36px;
  padding-inline: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-ink);
  text-decoration: none;
  font-size: 14px;
}

.groups-chip-more__item:hover { background: var(--color-surface-muted, #F6F7FB); }
.groups-chip-more__count { color: var(--color-text-muted); font-size: 12px; }

/* ---- Tabs -------------------------------------------------------- */

.groups-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border-soft);
}

.groups-tab {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding-inline: var(--space-3);
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: var(--fw-medium, 500);
}

.groups-tab.is-active { color: var(--color-primary-text); border-bottom-color: var(--color-primary); }
.groups-tab:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }

/* ---- Overview metrics -------------------------------------------- */

.groups-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0 0 var(--space-6);
  padding: 0;
  list-style: none;
}

.groups-metric {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "icon  n"
    "icon  label"
    "note  note";
  column-gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md-plus);
  background: var(--color-white);
}

.groups-metric__icon {
  grid-area: icon;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: hsl(249 90% 96%);
  color: var(--color-primary-text);
}

.groups-metric__n { grid-area: n; font-size: 22px; font-weight: 700; line-height: 1.2; color: var(--color-ink-heading); }
.groups-metric__label { grid-area: label; font-size: 13px; color: var(--color-text-muted); }
.groups-metric__note { grid-area: note; margin-top: var(--space-2); font-size: 12px; color: var(--color-text-muted); }

/* ---- Sections ---------------------------------------------------- */

.groups-section { margin-bottom: var(--space-8); }

.groups-section__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.groups-section__title { margin: 0; font-size: 20px; font-weight: 600; color: var(--color-ink-heading); }
.groups-section__count { font-size: 13px; color: var(--color-text-muted); }

.groups-section__all {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 32px;
  color: var(--color-primary-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: var(--fw-medium, 500);
}

.groups-section__all:hover { text-decoration: underline; }

/* ---- Featured cards ---------------------------------------------- */

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* The dir-card family is a four-area grid built for a left icon and a
   text column. A group card is a cover above a body, so inside
   .groups-grid the areas are replaced rather than fought with. */
.dir-card--group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  grid-template-areas: none;
}

.dir-card__cover {
  position: relative;
  aspect-ratio: 16 / 7;
  background: linear-gradient(135deg, hsl(249 90% 95%), hsl(217 90% 95%));
}

/* A group without its own cover gets a generated one in its own hue,
   so a shelf of four cards reads as four groups rather than four
   identical pale blocks. The hue arrives per card from the template;
   the fallback keeps the old gradient if it ever does not. */
.dir-card__cover--blank {
  background: linear-gradient(
    135deg,
    hsl(var(--dir-cover-hue, 249) 72% 62%),
    hsl(calc(var(--dir-cover-hue, 249) + 26) 68% 46%)
  );
}

/* The mark sits on a saturated cover now, so it keeps its own light
   plate rather than borrowing the cover's colour. */
.dir-card__cover--blank .dir-card__mark { background: var(--color-surface, #FFF); }

.dir-card__cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.dir-card__mark {
  position: absolute;
  inset-inline-start: var(--space-3);
  bottom: calc(var(--space-3) * -1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-white);
  background: var(--color-white);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.dir-card__mark img { width: 100%; height: 100%; object-fit: cover; }

.dir-card__initial {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary-text);
}

.dir-card__badge {
  position: absolute;
  inset-inline-end: var(--space-2);
  top: var(--space-2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-ink);
  font-size: 11px;
  font-weight: var(--fw-medium, 500);
}

.dir-card--group__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: calc(var(--space-3) + 12px) var(--space-4) var(--space-4);
}

.dir-card__name {
  grid-area: auto;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-ink-heading);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.dir-card__name:hover { color: var(--color-primary-text); }

.dir-card__desc {
  grid-area: auto;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dir-card__tags,
.groups-row__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.groups-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: hsl(249 90% 97%);
  color: var(--color-primary-text);
  font-size: 11px;
  white-space: nowrap;
}

/* One row, never two. Wrapping made the action sit beside the member
   count on a card with a short count and below it on the next card
   along, so a row of four cards had its buttons at two different
   heights — which reads as a rendering fault rather than as text of
   different lengths. The count shrinks and truncates instead. */
.dir-card__foot {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-2);
}

.dir-card__foot .dir-card__stat {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dir-card__foot .groups-join-form,
.dir-card__foot .groups-join { flex: 0 0 auto; }

.dir-card__stat,
.groups-row__members {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ---- The All Groups list ----------------------------------------- */

.groups-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.groups-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  grid-template-areas: none;
}

.groups-row__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: hsl(249 90% 96%);
  overflow: hidden;
  flex: 0 0 auto;
}

.groups-row__icon img { width: 100%; height: 100%; object-fit: cover; }
.dir-card__initial { font-size: 18px; font-weight: 700; color: var(--color-primary-text); }

.groups-row__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.groups-row__name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-ink-heading);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.groups-row__name:hover { color: var(--color-primary-text); }

.groups-row__desc {
  font-size: 13px;
  color: var(--color-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- The join control -------------------------------------------- */

.groups-join {
  min-height: 40px;
  white-space: nowrap;
}

.groups-join--block { width: 100%; justify-content: center; }

/* 8.651.0: the LABEL uses the success TEXT token, the border keeps the
   success accent.

   Both were `--color-success`, which resolves to #22C55E — measured at
   2.28:1 against the white card, where text needs 4.5:1. It failed on
   every joined card, so a member who had joined ten groups got ten
   serious contrast nodes, and a member who had joined none got a clean
   page. That is why 8.648.0 shipped it: the defect is invisible until
   somebody uses the feature.

   `--color-success-text` (#14853E) measures 4.72:1 and exists for
   exactly this. The border stays on the accent, which needs only 3:1
   as a non-text boundary and makes 3.26:1. */
.groups-join.is-joined { border-color: var(--color-success, #16A34A); color: var(--color-success-text, #14853E); }

.groups-join.is-pending,
.groups-join.is-locked,
.groups-join.is-closed {
  color: var(--color-text-muted);
  cursor: default;
  opacity: 0.85;
}

.groups-join-form { margin: 0; }

/* ---- Pager and empty --------------------------------------------- */

.groups-pager {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
  margin-top: var(--space-6);
}

.groups-pager .page-numbers {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding-inline: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-ink);
  text-decoration: none;
}

.groups-pager .page-numbers.current {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-white);
}

.groups-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md-plus);
  text-align: center;
}

.groups-empty__title { margin: 0; font-size: 16px; font-weight: 600; color: var(--color-ink-heading); }
.groups-empty__lede { margin: 0 0 var(--space-2); font-size: 14px; color: var(--color-text-muted); max-width: 46ch; }

/* ==================================================================
   Create a Group
   ================================================================== */

.groups-create {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  align-items: start;
  gap: var(--space-6);
}

.groups-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md-plus);
  background: var(--color-white);
}

.groups-step { display: flex; flex-direction: column; gap: var(--space-4); }

.groups-step + .groups-step { padding-top: var(--space-5); border-top: 1px solid var(--color-border-soft); }

.groups-step__head { display: flex; align-items: flex-start; gap: var(--space-3); }

.groups-step__n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-white);
  font-size: 13px;
  font-weight: 700;
}

.groups-step__title { margin: 0; font-size: 16px; font-weight: 600; color: var(--color-ink-heading); }
.groups-step__hint { margin: 2px 0 0; font-size: 13px; color: var(--color-text-muted); }

.groups-field { position: relative; display: flex; flex-direction: column; gap: 6px; }

.groups-field > label,
.groups-field legend {
  font-size: 14px;
  font-weight: var(--fw-medium, 500);
  color: var(--color-ink-heading);
}

.groups-field__required { color: var(--color-danger); }
.groups-field__optional { color: var(--color-text-muted); font-weight: 400; }
.groups-field__hint { margin: 0; font-size: 12px; color: var(--color-text-muted); }
.groups-field__error { margin: 0; font-size: 12px; color: var(--color-danger); }

.groups-field input[type="text"],
.groups-field input[type="search"],
.groups-field input[type="file"],
.groups-field select,
.groups-field textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  font: inherit;
  color: var(--color-ink);
}

.groups-field textarea { min-height: 6rem; resize: vertical; }

.groups-field input:focus-visible,
.groups-field select:focus-visible,
.groups-field textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.groups-field.is-invalid input,
.groups-field.is-invalid textarea,
.groups-field.is-invalid select { border-color: var(--color-danger); }

.groups-field__count {
  align-self: flex-end;
  font-size: 12px;
  color: var(--color-text-muted);
}

.groups-uploads { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: var(--space-4); }

/* The file input is the control; the zone is its visible surface.
   Moved off-screen rather than display:none, which would drop it out
   of the tab order and leave the zone unreachable by keyboard. */
.groups-upload__input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.groups-upload__label { font-size: 14px; font-weight: var(--fw-medium, 500); color: var(--color-ink-heading); }

.groups-upload__zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 7.5rem;
  padding: var(--space-4);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-muted, #F8F9FC);
  text-align: center;
  cursor: pointer;
}

.groups-upload__zone:hover { border-color: var(--color-primary); background: hsl(249 90% 98%); }

.groups-upload__input:focus-visible + .groups-upload__zone,
.groups-upload__zone:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* The input follows the zone in the DOM, so the focus ring is drawn
   with a sibling selector in the other direction too. */
.groups-upload:has(.groups-upload__input:focus-visible) .groups-upload__zone {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.groups-upload__icon { width: 24px; height: 24px; color: var(--color-primary-text); }
.groups-upload__zone strong { font-size: 14px; color: var(--color-ink-heading); }
.groups-upload__zone span { font-size: 12px; color: var(--color-text-muted); }

/* Scoped under the zone because `.groups-upload__zone span` already
   claims every span in here at 12px muted, and that beats a single
   class on the pill itself. */
.groups-upload__zone .groups-upload__pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--space-2);
  padding: 6px var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface, #FFF);
  color: var(--color-ink-heading);
  font-size: 12px;
  font-weight: var(--fw-medium, 500);
}

.groups-upload__zone .groups-upload__pill span { font-size: 12px; color: inherit; }

.groups-upload__chosen:not(:empty) {
  margin-top: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: hsl(249 90% 96%);
  color: var(--color-primary-text);
  font-size: 11px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Privacy chooser --------------------------------------------- */

.groups-privacy {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  border: 0;
}

.groups-privacy legend { margin-bottom: var(--space-2); }

.groups-privacy__option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  cursor: pointer;
}

/* The chooser is radio inputs, not clickable divs: it arrives
   keyboard-operable, announced as a group, and submits without
   script. The visual selection follows the real control. */
.groups-privacy__option:has(input:checked) {
  border-color: var(--color-primary);
  background: hsl(249 90% 98%);
}

.groups-privacy__option:has(input:focus-visible) {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.groups-privacy__option input { margin-top: 3px; flex: 0 0 auto; }
.groups-privacy__icon { display: inline-flex; color: var(--color-primary-text); }
.groups-privacy__copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.groups-privacy__copy strong { font-size: 14px; color: var(--color-ink-heading); }
.groups-privacy__copy span { font-size: 12px; color: var(--color-text-muted); }

/* ---- Switches ---------------------------------------------------- */

.groups-switches { display: flex; flex-direction: column; gap: var(--space-3); }

.groups-switch { display: flex; align-items: flex-start; gap: var(--space-3); cursor: pointer; }

/* The checkbox itself is moved off-screen rather than hidden: a
   display:none control is not focusable and not announced. */
.groups-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.groups-switch__track {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  margin-top: 2px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  transition: background 120ms ease;
}

.groups-switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-white);
  transition: transform 120ms ease;
}

.groups-switch input:checked + .groups-switch__track { background: var(--color-primary); }
.groups-switch input:checked + .groups-switch__track::after { transform: translateX(18px); }

.groups-switch input:focus-visible + .groups-switch__track {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.groups-switch__copy { display: flex; flex-direction: column; gap: 2px; }
.groups-switch__copy strong { font-size: 14px; color: var(--color-ink-heading); }
.groups-switch__copy span { font-size: 12px; color: var(--color-text-muted); }

.groups-form__note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: hsl(217 90% 97%);
  font-size: 13px;
  color: var(--color-ink);
}

.groups-form__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border-soft);
}

.groups-form__actions .btn { min-height: 44px; }

/* ---- Preview and tips -------------------------------------------- */

.groups-aside { display: flex; flex-direction: column; gap: var(--space-4); }

.groups-preview,
.groups-tips {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md-plus);
  background: var(--color-white);
}

.groups-preview__head { display: flex; align-items: flex-start; gap: var(--space-2); margin-bottom: var(--space-3); color: var(--color-primary-text); }
.groups-preview__title { margin: 0; font-size: 15px; font-weight: 600; color: var(--color-ink-heading); }
.groups-preview__hint { margin: 2px 0 0; font-size: 12px; color: var(--color-text-muted); }

/* Only the chosen privacy's icon shows. All three are in the markup so
   switching costs no request and the right one is already rendered with
   script off. */
.groups-preview__pico { display: none; line-height: 0; }

.groups-preview__privacy[data-privacy="public"] .groups-preview__pico[data-pico="public"],
.groups-preview__privacy[data-privacy="private"] .groups-preview__pico[data-pico="private"],
.groups-preview__privacy[data-privacy="request"] .groups-preview__pico[data-pico="request"] {
  display: inline-flex;
}

/* The board's Join Group button, as a picture of one. Deliberately not
   a button and not focusable: see the template. */
.groups-preview__join {
  display: block;
  margin-top: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  background: hsl(249 90% 95%);
  color: var(--color-primary-text);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.dir-card--preview { border-color: var(--color-border-soft); }

.groups-tips__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  font-size: 15px;
  font-weight: 600;
  color: var(--color-ink-heading);
}

.groups-tips__list { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }

.groups-tips__list li {
  position: relative;
  padding-inline-start: var(--space-5);
  font-size: 13px;
  color: var(--color-ink);
}

.groups-tips__list li::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-success, #16A34A);
}

/* The tick inside the circle, which the board draws and a plain dot
   does not say. Two borders on a rotated box: it scales with the
   circle, costs no asset, and stays white on green in dark mode where
   the circle keeps its own colour. */
.groups-tips__list li::after {
  content: "";
  position: absolute;
  inset-inline-start: 5px;
  top: 6px;
  width: 4px;
  height: 8px;
  border: solid #FFF;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ==================================================================
   One group
   ================================================================== */

.groups-single {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  align-items: start;
  gap: var(--space-6);
}

.groups-single__main { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }

.groups-single__cover { border-radius: var(--radius-md-plus); overflow: hidden; }
.groups-single__cover img { width: 100%; height: auto; display: block; }

.groups-single__h2 { margin: 0 0 var(--space-2); font-size: 18px; font-weight: 600; color: var(--color-ink-heading); }

.groups-single__about,
.groups-single__locked,
.groups-single__soon,
.groups-requests,
.groups-panel {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md-plus);
  background: var(--color-white);
}

.groups-single__body { font-size: 15px; line-height: 1.6; color: var(--color-ink); }
.groups-single__soon-note { margin: 0; font-size: 14px; color: var(--color-text-muted); }

.groups-single__locked p { margin: 0 0 var(--space-3); font-size: 14px; color: var(--color-text-muted); }

.groups-requests__list { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }

.groups-requests__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-border-soft);
}

.groups-requests__item:first-child { border-top: 0; }

.groups-requests__who { display: inline-flex; align-items: center; gap: var(--space-2); min-width: 0; }
.groups-requests__who > span { display: flex; flex-direction: column; min-width: 0; }
.groups-requests__avatar { border-radius: 50%; }
.groups-requests__when { font-size: 12px; color: var(--color-text-muted); }
.groups-requests__actions { display: inline-flex; gap: var(--space-2); }
.groups-requests__actions form { margin: 0; }

.groups-single__side { display: flex; flex-direction: column; gap: var(--space-4); }

.groups-panel__head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }

.groups-panel__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: var(--radius-md);
  background: hsl(249 90% 96%);
  color: var(--color-primary-text);
  font-weight: 700;
  overflow: hidden;
}

.groups-panel__mark img { width: 100%; height: 100%; object-fit: cover; }
.groups-panel__head > div { display: flex; flex-direction: column; min-width: 0; }
.groups-panel__head strong { font-size: 15px; color: var(--color-ink-heading); overflow-wrap: anywhere; }
.groups-panel__cat { font-size: 12px; color: var(--color-text-muted); }

.groups-panel__title { margin: 0 0 var(--space-3); font-size: 15px; font-weight: 600; color: var(--color-ink-heading); }

.groups-panel__facts { display: flex; flex-direction: column; gap: var(--space-2); margin: 0 0 var(--space-3); padding: 0; list-style: none; }

.groups-panel__facts li { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); font-size: 13px; }
.groups-panel__facts span { color: var(--color-text-muted); }
.groups-panel__facts strong { color: var(--color-ink-heading); }

.groups-panel__leave { margin: 0; }

.groups-panel__manage {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--color-primary-text);
}

.groups-roster { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.groups-roster__item { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.groups-roster__avatar { border-radius: 50%; flex: 0 0 auto; }
.groups-roster__name { font-size: 13px; color: var(--color-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.groups-roster__role {
  margin-inline-start: auto;
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
  background: hsl(249 90% 97%);
  color: var(--color-primary-text);
  font-size: 11px;
  white-space: nowrap;
}

/* ==================================================================
   Narrow
   ================================================================== */

@media (max-width: 1023.98px) {
  .groups-create,
  .groups-single { grid-template-columns: minmax(0, 1fr); }

  /* The preview follows the form it previews rather than leading it:
     at this width it would otherwise push the first field a screen
     down, and the preview of an empty form says nothing. */
  .groups-aside { order: 2; }
}

@media (max-width: 767.98px) {
  .groups-page { padding-inline: var(--space-4); padding-block: var(--space-5) var(--space-8); }

  /* §3: search plus a filter control, not three stacked selects. The
     selects submit on change, so each is one tap rather than a tap
     and a Search press. */
  .groups-controls { gap: var(--space-2); }
  .groups-search { flex: 1 1 100%; }
  .groups-select { flex: 1 1 calc(50% - var(--space-1)); }
  .groups-select select { width: 100%; }
  .groups-controls__go { display: none; }

  /* The chip row scrolls sideways rather than wrapping to four rows.
     Labels keep their size — a chip shrunk until it fits is a chip
     nobody can read. */
  .groups-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: var(--space-1);
  }

  .groups-chips::-webkit-scrollbar { display: none; }

  .groups-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .groups-metric { padding: var(--space-3); }
  .groups-metric__icon { width: 32px; height: 32px; }
  .groups-metric__n { font-size: 18px; }
  .groups-metric__note { display: none; }

  .groups-grid { grid-template-columns: minmax(0, 1fr); }

  /* §3 again: the list becomes cards rather than a squeezed table.
     The action goes full width underneath, which is where a thumb
     expects it. */
  .groups-row {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "icon text"
      "tags tags"
      "meta meta"
      "act  act";
    row-gap: var(--space-2);
  }

  .groups-row__icon { grid-area: icon; }
  .groups-row__text { grid-area: text; }
  .groups-row__tags { grid-area: tags; }
  .groups-row__members { grid-area: meta; }
  .groups-row__action { grid-area: act; }
  .groups-row__action .groups-join { width: 100%; justify-content: center; }
  .groups-row__desc { -webkit-line-clamp: 2; }

  .groups-form { padding: var(--space-4); }
  .groups-privacy { grid-template-columns: minmax(0, 1fr); }
  .groups-form__actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* ==================================================================
   Dark
   ================================================================== */

html.jdev-dark .groups-search input,
html.jdev-dark .groups-select select,
html.jdev-dark .groups-chip,
html.jdev-dark .groups-metric,
html.jdev-dark .dir-card--group,
html.jdev-dark .groups-row,
html.jdev-dark .groups-form,
html.jdev-dark .groups-preview,
html.jdev-dark .groups-tips,
html.jdev-dark .groups-panel,
html.jdev-dark .groups-single__about,
html.jdev-dark .groups-single__locked,
html.jdev-dark .groups-single__soon,
html.jdev-dark .groups-requests,
html.jdev-dark .groups-privacy__option,
html.jdev-dark .groups-chip-more__panel {
  background: var(--color-surface, #14161F);
  border-color: var(--color-border, #2A2D3A);
  color: var(--color-ink, #E7E9F2);
}

/* The preview's Join pill is a pale literal under a token-coloured
   label, which is the exact shape the dark-mode gate fails. Same
   treatment the step tiles get one level up. */
html.jdev-dark .groups-preview__join {
  background: hsl(249 40% 22%);
  color: var(--color-ink, #E7E9F2);
}

html.jdev-dark .groups-tag,
html.jdev-dark .groups-metric__icon,
html.jdev-dark .groups-row__icon,
html.jdev-dark .groups-panel__mark,
html.jdev-dark .groups-roster__role {
  background: rgba(109, 94, 245, 0.16);
}

html.jdev-dark .groups-form__note { background: rgba(59, 130, 246, 0.12); }
html.jdev-dark .dir-card__badge { background: rgba(20, 22, 31, 0.9); color: var(--color-ink, #E7E9F2); }
