/* ==========================================================================
   Button group
   .btn-group              buttons joined into one control
   .btn-group-vertical     stacked
   .btn-group-xs/-sm/-lg   size every button in the group (see button.css)
   .btn-group-segmented    a switch: tray + raised active item (views, filters)
                           + .btn-group-<color> colors the selected item (+ .btn-group-subtle … -deep for its strength)
   .btn-toolbar            a row of groups / buttons
   Toggles without JS:     <label class="btn"><input type="radio" class="btn-check" name="v"> Day</label>
   ========================================================================== */

.btn-group,
.btn-group-vertical {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
  isolation: isolate;
}
.btn-group-vertical { flex-direction: column; align-items: stretch; }

.btn-group > *,
.btn-group-vertical > * { position: relative; flex: 0 1 auto; }

/* Keep the hovered / focused / active button on top of its neighbours */
:is(.btn-group, .btn-group-vertical) > :is(:hover, :focus-visible, :focus-within, .active, [aria-pressed="true"]) { z-index: 1; }

/* Flat: a 1px gap (the background shows through) separates filled buttons… */
.btn-group > * + * { margin-inline-start: 1px; }
.btn-group-vertical > * + * { margin-block-start: 1px; }
/* …outline buttons share their border instead */
.btn-group > .btn-outline + .btn-outline { margin-inline-start: calc(-1 * var(--mo-border-width)); }
.btn-group-vertical > .btn-outline + .btn-outline { margin-block-start: calc(-1 * var(--mo-border-width)); }

/* Only the outer corners stay rounded */
/* (:where keeps the split-button exception from raising specificity above the segmented style) */
.btn-group > :not(:last-child):not(:where(:has(+ .menu:last-child))) { border-start-end-radius: 0; border-end-end-radius: 0; }
.btn-group > :not(:first-child) { border-start-start-radius: 0; border-end-start-radius: 0; }
.btn-group-vertical > :not(:last-child) { border-end-start-radius: 0; border-end-end-radius: 0; }
.btn-group-vertical > :not(:first-child) { border-start-start-radius: 0; border-start-end-radius: 0; }

/* Segmented control ------------------------------------------------------- */
.btn-group-segmented {
  /* the selected item: a raised surface (in dark mode clearly lighter than the tray) */
  --mo-segment-active: light-dark(var(--mo-bg-raised), color-mix(in oklab, var(--mo-fg-body) 17%, var(--mo-bg-surface)));
  --mo-segment-on: var(--mo-fg-body);
  gap: 2px;
  padding: 3px;
  background: color-mix(in oklab, var(--mo-fg-body) 6%, transparent);  /* reads on any background */
  border-radius: calc(var(--mo-radius-control) + 2px);
}
.btn-group.btn-group-segmented > * + * { margin: 0; }
.btn-group.btn-group-segmented > * {
  --mo-btn-height: calc(var(--mo-control-height) - 6px);
  --mo-btn-color: var(--mo-fg-2);
  --mo-btn-bg: transparent;
  --mo-btn-border: transparent;
  --mo-btn-hover-color: var(--mo-fg-body);
  --mo-btn-hover-bg: color-mix(in oklab, var(--mo-fg-body) 6%, transparent);
  --mo-btn-hover-border: transparent;
  --mo-btn-active-bg: var(--mo-btn-hover-bg);
  border-radius: var(--mo-radius-control);
}
/* The selected item */
.btn-group.btn-group-segmented > :is(.active, [aria-pressed="true"], [aria-selected="true"], :has(> .btn-check:checked)) {
  --mo-btn-color: var(--mo-segment-on);
  --mo-btn-bg: var(--mo-segment-active);
  --mo-btn-hover-bg: var(--mo-segment-active);
  --mo-btn-active-bg: var(--mo-segment-active);
  color: var(--mo-btn-color);
  background-color: var(--mo-btn-bg);   /* flat: the selection reads by color alone, no shadow */
}
/* A colored selection: .btn-group-green — the soft default fill; a strength makes it lighter or stronger */
.btn-group-segmented:is(/*@colors btn-group*/, /*@themes*/) { --mo-segment-active: var(--mo-theme-fill); --mo-segment-on: var(--mo-theme-fill-text); }
.btn-group-segmented.btn-group-subtle { --mo-segment-active: var(--mo-theme-subtle); --mo-segment-on: var(--mo-theme-subtle-text); }
.btn-group-segmented.btn-group-soft   { --mo-segment-active: var(--mo-theme-soft);   --mo-segment-on: var(--mo-theme-soft-text); }
.btn-group-segmented.btn-group-solid  { --mo-segment-active: var(--mo-theme-solid);  --mo-segment-on: var(--mo-theme-solid-text); }
.btn-group-segmented.btn-group-vivid  { --mo-segment-active: var(--mo-theme-vivid);  --mo-segment-on: var(--mo-theme-vivid-text); }
.btn-group-segmented.btn-group-deep   { --mo-segment-active: var(--mo-theme-deep);   --mo-segment-on: var(--mo-theme-deep-text); }
.btn-group.btn-group-segmented.btn-group-sm > * { --mo-btn-height: calc(var(--mo-control-height-sm) - 6px); }
.btn-group.btn-group-segmented.btn-group-lg > * { --mo-btn-height: calc(var(--mo-control-height-lg) - 6px); }

/* Toolbar ------------------------------------------------------------------ */
.btn-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
}

/* Toggle buttons with a real radio / checkbox inside (no JS) ----------------
   The input is hidden but still focusable and form-submittable.             */
.btn-check {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}
:is(/*@btn*/):has(> .btn-check:checked) {
  color: var(--mo-btn-hover-color);
  background-color: var(--mo-btn-active-bg);
  border-color: var(--mo-btn-hover-border);
}
:is(/*@btn*/):has(> .btn-check:focus-visible) {
  z-index: 1;
  outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring);
  outline-offset: 1px;
}
:is(/*@btn*/):has(> .btn-check:disabled) {
  pointer-events: none;
  opacity: .5;
}
