/* ==================================================================================================
   Toolbar — owner: design-system agent. ONE toolbar for every task view (board, list,
   calendar, timeline, my tasks, insights…). Markup + rules: docs/design-system.md "Toolbar".
   r4 «Birge OS»: tool buttons, the search field, filter pills and active filters are capsules;
   an ON filter is the iOS tinted look (--accent-soft, no hairline).

   .toolbar                 row container (a size container: `toolbar`) — put it in
                            {% block project_toolbar %} (project views: header row 2) or at the top
                            of the page content (other pages)
     .toolbar__group        a cluster of tools (4px gaps)
     .toolbar__spacer       pushes the following groups to the end
     .toolbar__sep          1px hairline between groups
   .toolbar-search          components/toolbar_search.html — a quiet field (stays a field while the
                            toolbar is ≥ 360px wide; below that it collapses to its
                            icon — expands on focus / while it holds text)
   .toolbar-btn             28px tool button: plain until active. Variants/states:
                            [aria-expanded="true"] (its popover is open) · .is-active /
                            [aria-pressed="true"] / label:has(input:checked) (a filter or toggle is
                            on: accent tint) · --icon (square) · __label (hides in narrow toolbars
                            when the button also has an icon: .toolbar-btn--collapsible) · __count
                            (accent) / __count--muted (a plain number)
   .toolbar[data-toolbar-fit] app.js adds .is-compact when the labels don't fit (any language)
   .filter-pill             outline pill for one-tap filters in a row (+ __dot, __text, __count,
                            __check, --xs)
   .filter-panel           popover content: __grid, __section, __title, __list, __empty,
                            .filter-option (+ __text, __count) — checkboxes/radios inside
   .display-panel           popover content for Group / Sort / view options: __row (label +
                            control), __label, __section
   .active-filters          components/active_filters.html — the active filters as removable
                            chips (.active-filter: __key, __value, __remove) + count + "Clear all"
   ================================================================================================== */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  container: toolbar / inline-size;
}
.toolbar__group {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.toolbar__group--grow {
  flex: 1 1 auto;
}
.toolbar__spacer {
  flex: 1 1 auto;
  min-width: 0;
}
.toolbar__sep {
  flex-shrink: 0;
  width: 0.5px;
  height: 16px;
  margin-inline: 3px;
  background: var(--line-strong);
}

/* -- Tool button --------------------------------------------------------------------------------- */
.toolbar-btn {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: var(--control-h-sm);
  padding: 0 10px;
  border: 0.5px solid transparent;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--dur-1) ease,
    border-color var(--dur-1) ease,
    color var(--dur-1) ease,
    transform var(--dur-snappy) var(--spring-snappy);
}
.toolbar-btn:hover {
  background: var(--fill-1);
  color: var(--text);
}
.toolbar-btn:active {
  background: var(--fill-2);
  transform: scale(0.96);
  transition-duration: var(--dur-1);
}
.toolbar-btn[aria-expanded="true"] {
  background: var(--fill-2);
  color: var(--text);
}
.toolbar-btn:focus-visible,
.toolbar-btn:has(> input:focus-visible) {
  outline: 2px solid var(--focus-outline);
  outline-offset: 1px;
}
/* A filter/toggle that is ON: the iOS tinted look, so "something is filtered" reads at a glance. */
.toolbar-btn.is-active,
.toolbar-btn[aria-pressed="true"],
.toolbar-btn:has(> input:checked) {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.toolbar-btn.is-active:hover,
.toolbar-btn[aria-pressed="true"]:hover,
.toolbar-btn:has(> input:checked):hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}
/* label.toolbar-btn + hidden checkbox = a toggle (e.g. "Hide completed", "My tasks"). */
.toolbar-btn > input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: default;
}
.toolbar-btn .icon {
  flex-shrink: 0;
}
.toolbar-btn__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toolbar-btn__count {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  margin-right: -2px;
  padding: 0 4px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}
.toolbar-btn__count:empty,
.toolbar-btn__count[hidden] {
  display: none;
}
/* A plain number (how many there are, not "needs you"): the inbox's Mentions 8, Assigned 3… */
.toolbar-btn__count--muted {
  min-width: 0;
  margin: 0;
  padding: 0;
  background: none;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}
.toolbar-btn.is-active > .toolbar-btn__count--muted,
.toolbar-btn[aria-pressed="true"] > .toolbar-btn__count--muted {
  color: inherit;
}
.toolbar-btn--icon {
  width: var(--control-h-sm);
  padding: 0;
}
.toolbar-btn--bordered {
  border-color: light-dark(rgb(0 0 0 / 0.12), rgb(255 255 255 / 0.08));
  background: var(--btn-bg, light-dark(var(--surface), rgb(255 255 255 / 0.1)));
  box-shadow: var(--shadow-control);
}
.toolbar-btn--bordered:hover {
  background: light-dark(var(--surface-2), rgb(255 255 255 / 0.14));
}
/* Narrow toolbars: collapsible buttons keep their icon (the label stays for screen readers and in
   the tooltip — give them data-tooltip with the same text). Toolbars with data-toolbar-fit are
   measured instead (below): labels stay while they fit. */
.toolbar-btn--collapsible[data-tooltip]::after {
  display: none;
}
@container toolbar (max-width: 720px) {
  .toolbar:not([data-toolbar-fit]) .toolbar-btn--collapsible {
    width: var(--control-h-sm);
    padding: 0;
  }
  .toolbar:not([data-toolbar-fit]) .toolbar-btn--collapsible > .toolbar-btn__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .toolbar:not([data-toolbar-fit]) .toolbar-btn--collapsible > .toolbar-btn__count {
    position: absolute;
    top: -4px;
    right: -4px;
    box-shadow: 0 0 0 2px var(--bg);
  }
  .toolbar:not([data-toolbar-fit]) .toolbar-btn--collapsible > .toolbar-btn__count--muted {
    display: none;
  }
  /* low specificity: the tooltip still only lays out while hovered/focused (overlays.css) */
  :where(.toolbar:not([data-toolbar-fit])) .toolbar-btn--collapsible[data-tooltip]:where(:not([aria-expanded="true"]))::after {
    display: block;
  }
}
/* .toolbar[data-toolbar-fit]: app.js measures the toolbar with every label shown and, when something
   would be cut or scroll, collapses its collapsible buttons one by one from the end (.is-collapsed)
   — for any language, at any width (the inbox tabs in ky at 1440). Same look as above. */
.toolbar .toolbar-btn--collapsible.is-collapsed {
  width: var(--control-h-sm);
  padding: 0;
}
.toolbar .toolbar-btn--collapsible.is-collapsed > .toolbar-btn__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.toolbar .toolbar-btn--collapsible.is-collapsed > .toolbar-btn__count {
  position: absolute;
  top: -4px;
  right: -4px;
  box-shadow: 0 0 0 2px var(--bg);
}
.toolbar .toolbar-btn--collapsible.is-collapsed > .toolbar-btn__count--muted {
  display: none;
}
.toolbar-btn--collapsible:where(.is-collapsed:not([aria-expanded="true"]))[data-tooltip]::after {
  display: block;
}

/* -- Filter pill ---------------------------------------------------------------------------------
   One-tap filters in a row (people by team, chat All · Unread · Direct…, the Display popover's
   "show on cards" toggles): a quiet outline pill; ON (.is-active / [aria-pressed="true"] /
   label:has(input:checked)) reads like an active toolbar filter — accent tint + hairline.
   __dot (identity: data-color on the pill), __text (ellipsizes), __count (accent counter, hidden
   when empty), __check (shows only while ON). --xs: 24px for popovers. Rows of pills: put them in
   a flex row with data-scroll-fade (fade edges, the active pill kept in view). */
.filter-pill {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: var(--control-h-sm);
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--fill-1);
  box-shadow: none;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition:
    background-color var(--dur-1) ease,
    box-shadow var(--dur-1) ease,
    color var(--dur-1) ease;
}
.filter-pill:hover {
  background: var(--fill-2);
  color: var(--text);
}
.filter-pill:active {
  background: var(--fill-3);
}
.filter-pill:focus-visible,
.filter-pill:has(> input:focus-visible) {
  outline: 2px solid var(--focus-outline);
  outline-offset: 1px;
}
.filter-pill.is-active,
.filter-pill[aria-pressed="true"],
.filter-pill:has(> input:checked) {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.filter-pill.is-active:hover,
.filter-pill[aria-pressed="true"]:hover,
.filter-pill:has(> input:checked):hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}
.filter-pill > input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: default;
}
.filter-pill__dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tone, var(--text-3));
}
.filter-pill__text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filter-pill__count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-right: -4px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}
.filter-pill__count:empty,
.filter-pill__count[hidden] {
  display: none;
}
.filter-pill__check {
  flex-shrink: 0;
  margin-left: -2px;
  opacity: 0;
  transition: opacity var(--dur-1) ease;
}
.filter-pill:is(.is-active, [aria-pressed="true"], :has(> input:checked)) .filter-pill__check {
  opacity: 1;
}
.filter-pill--xs {
  gap: 5px;
  height: var(--control-h-xs);
  padding: 0 9px 0 7px;
  font-size: var(--fs-xs);
}
@media (pointer: coarse) {
  .filter-pill:not(.filter-pill--xs) {
    height: 32px;
    padding: 0 12px;
  }
}

/* -- Search -------------------------------------------------------------------------------------- */
.toolbar-search {
  position: relative;
  display: inline-flex;
  flex: 0 1 220px;
  align-items: center;
  min-width: 0;
  height: var(--control-h-sm);
  border: 0;
  border-radius: var(--radius-full);
  background: var(--fill-2);
  color: var(--text-3-on-fill);
  cursor: text;
  transition:
    flex-basis var(--dur-2) var(--ease-out),
    background-color var(--dur-1) ease,
    border-color var(--dur-1) ease,
    box-shadow var(--dur-2) ease;
}
.toolbar-search:hover {
  background: var(--fill-3);
}
.toolbar-search > .icon {
  position: absolute;
  left: 9px;
  pointer-events: none;
}
.toolbar-search > input {
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 10px 0 29px;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.toolbar-search > input::placeholder {
  color: var(--text-3-on-fill);
}
.toolbar-search > input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}
.toolbar-search:focus-within {
  background: var(--fill-2);
  box-shadow: 0 0 0 3.5px var(--focus-ring);
}
/* Holding a query = an active filter (tinted like an ON filter). */
.toolbar-search:has(> input:not(:placeholder-shown)) {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
@container toolbar (max-width: 359px) {
  .toolbar-search:not(:focus-within):not(:has(> input:not(:placeholder-shown))) {
    flex: 0 0 var(--control-h-sm);
    background: transparent;
    color: var(--text-2);
    cursor: default;
  }
  .toolbar-search:not(:focus-within):not(:has(> input:not(:placeholder-shown))):hover {
    background: var(--fill-1);
  }
  .toolbar-search:not(:focus-within):not(:has(> input:not(:placeholder-shown))) > input {
    padding: 0;
    cursor: default;
  }
  .toolbar-search:not(:focus-within):not(:has(> input:not(:placeholder-shown))) > input::placeholder {
    color: transparent;
  }
  .toolbar-search:focus-within,
  .toolbar-search:has(> input:not(:placeholder-shown)) {
    flex-basis: 200px;
  }
}
@media (pointer: coarse), (max-width: 767px) {
  .toolbar-search > input {
    font-size: 16px; /* no iOS zoom on focus */
  }
}

/* -- Filter panel (popover content) -------------------------------------------------------------- */
.filter-panel {
  min-width: 240px;
  padding: 6px;
}
.filter-panel--wide {
  width: min(880px, calc(100vw - 16px));
  max-width: min(880px, calc(100vw - 16px));
}
.filter-panel__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 4px 12px;
}
.filter-panel__section {
  min-width: 0;
}
.filter-panel__title {
  padding: 8px 8px 4px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}
.filter-panel__list {
  display: flex;
  flex-direction: column;
  max-height: 248px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.filter-panel__empty {
  padding: 4px 8px 8px;
  color: var(--text-3);
  font-size: var(--fs-sm);
}
.filter-panel__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin: 6px -6px -6px;
  padding: 6px;
  border-top: 0.5px solid var(--line);
}
.filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: var(--row-h);
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  cursor: default;
  transition: background-color var(--dur-1) ease;
}
.filter-option:hover {
  background: var(--fill-1);
}
.filter-option > input {
  margin: 0;
}
.filter-option__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filter-option__count {
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

/* -- Display panel (group / sort / view options) ------------------------------------------------- */
.display-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 280px;
  padding: 8px;
}
/* Closed, it must stay display:none — the UA's [popover] rule loses to the display:flex above (an
   invisible panel caught the clicks around the toolbar). */
.display-panel[popover]:not(:popover-open):not(.is-open) {
  display: none;
}
.display-panel__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding: 0 4px;
}
.display-panel__label {
  color: var(--text-2);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.display-panel__row > .input,
.display-panel__row > select {
  width: auto;
  max-width: 60%;
}
.display-panel__section + .display-panel__section {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 0.5px solid var(--line);
}

/* -- Active filters (removable chips) ------------------------------------------------------------ */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.active-filters:not(:has(.active-filter)) {
  display: none;
}
.active-filters__count {
  margin-right: 2px;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.active-filter {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--fill-1);
  box-shadow: none;
  font-size: var(--fs-xs);
  line-height: 1;
  white-space: nowrap;
}
.active-filter__key {
  flex-shrink: 0;
  padding-left: 10px;
  color: var(--text-3-on-fill);
}
.active-filter__value {
  min-width: 0;
  max-width: 200px;
  overflow: hidden;
  padding: 0 2px 0 4px;
  color: var(--text);
  font-weight: var(--fw-medium);
  text-overflow: ellipsis;
}
.active-filter__value:first-child {
  padding-left: 10px;
}
.active-filter__remove {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 2px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-3-on-fill);
  cursor: default;
}
.active-filter__remove:hover {
  background: var(--fill-2);
  color: var(--text);
}
.active-filter__remove:focus-visible {
  outline: 2px solid var(--focus-outline);
  outline-offset: -2px;
}
