/* The legislation picker.
 *
 * Its own file rather than more of calendar_events.css, which is already at the length this
 * repo guards for. Nothing outside the picker uses these rules.
 *
 * Scoped on `.al-picker`, not on a modal id. The first version keyed every selector to
 * `#associated-legislation-modal`, which is the edit screen's dialog; the create and copy
 * screens open the same partial inside `#myModal`, so the entire redesign rendered unstyled
 * there. A class the partial can carry works wherever the partial is used.
 *
 * The shape follows the data. Per tenant the picker holds up to 1,771 documents across as
 * many as 14 jurisdictions, and an event attaches a median of one clause. So the search
 * leads and a result is a clause: there is nothing to open, and the two facets narrow a
 * search that matched more than the list shows.
 *
 * The rules for the jurisdiction accordion and the per-document clause list are gone with the
 * accordion itself. They styled a shape the picker no longer has.
 */

.al-picker {
  --al-step: .5rem;   /* allow-length: the picker's spacing step, the one value the rest derive from */
  --al-line: var(--bs-border-width) solid var(--bs-border-color);
  --al-muted: #565e6b; /* allow-length: n/a, colour token: the contrast-safe muted grey used across this module */
}

/* One grid per clause list, each row a `display:contents` member; its tracks come from legislation_columns.COLUMNS. */
.al-picker .al-hits {
  display: grid;
  align-items: baseline;
  column-gap: .5rem; /* allow-length: one spacing step, matching --al-step */
}

/* A clause the record already cites. Quieter than a live row, because it is context rather
   than a choice: the tick is disabled and the state column says why. */
.al-picker .al-hit-cited > * { color: var(--al-muted); }
.al-picker .al-hit-cited { cursor: default; }
.al-picker .al-hit-state { white-space: nowrap; font-size: .75rem; } /* allow-length: matches the column-header step */

.al-picker .al-hit {
  display: contents;
  cursor: pointer;
}

.al-picker .al-hit > * {
  border-top: var(--al-line);
  padding: .25rem 0; /* allow-length: a dense row, sized to one line of clause text */
  min-width: 0;
}

.al-picker .al-hit-head > * {
  border-top: 0;
  font-weight: 500;
  color: var(--al-muted);
  font-size: .75rem; /* allow-length: a column header, one step under the row text */
  text-transform: none;
}

.al-picker .al-hit:hover > * { background: #f1f3f8; } /* allow-length: n/a, colour token: the hover tone shared with the rest of the module */

/* The clause: its number and its text, the one place two values share a cell, because the
   number is a label for the text rather than an independent fact about the row. */
.al-picker .al-hit-clause { display: flex; gap: .4rem; /* allow-length: separates a clause number from its text */ min-width: 0; }
.al-picker .al-hit-name { font-weight: 600; white-space: nowrap; }
.al-picker .al-hit-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--al-muted);
}

/* Unbounded, so it clips with the full name in the title attribute rather than wrapping the
   row to two lines and breaking the rhythm of the list. */
.al-picker .al-hit-doc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.al-picker .al-hit-jur { color: var(--al-muted); white-space: nowrap; }

.al-picker .al-result-count {
  margin: 0 0 var(--al-step);
  color: var(--al-muted);
  font-size: .8rem; /* allow-length: a supporting line under the facets */
}

/* The search owns the top of the dialog and stays put while results scroll under it. */
.al-picker .al-search {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  gap: calc(var(--al-step) / 2);
  padding-bottom: var(--al-step);
  background: var(--bs-body-bg, #fff);
  border-bottom: var(--al-line);
}

/* The two facets, on one line under the search box. Sized to their content: a full-width
   select for "All jurisdictions" would claim half the dialog for a control usually left
   alone. Each carries its own visible label, because a bare select states the value it is
   set to and never the question it answers. */
.al-picker .al-facets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem; /* allow-length: two labelled controls reading as one row */
  padding: var(--al-step) 0;
}
.al-picker .al-facets .flabel { margin: 0; }
.al-picker .al-facets .form-select { width: auto; max-width: 14rem; /* allow-length: fits the longest jurisdiction name */ }

/* Search highlight. The server wraps matched runs in <mark class="search-match">; without a
   style it inherited the browser's yellow block. This is a soft tinted highlight so you can
   see WHY a result matched what you typed. */
.al-picker mark.search-match, .al-picker .search-match {
  background: var(--al-hl, rgba(245, 159, 46, .28));
  color: inherit;
  padding: 0 .1em; border-radius: 2px; /* allow-length: a snug highlight around the run */
}

.al-picker .al-empty {
  margin: calc(var(--al-step) * 3) 0;
  color: var(--al-muted);
  text-align: center;
}

/* The picker's form wraps the modal body and footer, which breaks Bootstrap's scrollable
   modal: that layout caps the content height and scrolls the body only when the body and
   footer are direct children of `.modal-content`. With a `<form>` in between, nothing caps
   the height, so the whole list runs off the bottom of the screen and the footer, carrying
   the "Use selected requirements" submit button, goes with it. This threads the flex chain
   through the form: the form fills the content as a column, the body scrolls, the footer
   stays pinned. `:has(.al-picker)` scopes it to this picker on both the edit dialog and the
   create/copy `#myModal`. */
/* Rounded, not a sharp square. `overflow:hidden` clips the scrolling body to the rounded
   corners so the header and footer keep them. */
.modal-content:has(.al-picker) { border-radius: 0.75rem; } /* allow-length: a soft dialog corner */
.modal-dialog-scrollable .modal-content:has(.al-picker) { overflow: hidden; }
.modal-content:has(.al-picker) > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}
.modal-content:has(.al-picker) > form > .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.modal-content:has(.al-picker) > form > .modal-footer { flex: 0 0 auto; }
