/* ============================================================
   Column header menu — shared component (static/js/column_menu.js)

   One floating menu, reused by every table that opts in. A table
   declares its columns with data-col-* attributes on each <th> and
   calls ColumnMenu.attach(); nothing here is table-specific.

   Lives next to pagination.css / tables.css as an app-wide primitive:
   loaded in base.html for every page, inert until a page attaches.
   ============================================================ */

/* ── The header itself ──────────────────────────────────────── */
/* Opting a header in makes it feel clickable and reserves room for the hover
   caret, so the label never shifts when it appears. The reserve is deliberately
   small — it applies to EVERY opted-in header, and a 16- or 22-column table pays
   it once per column. !important is needed to beat Bootstrap's
   `.table > :not(caption) > * > *` cell padding, which is more specific. */
th[data-col-menu] {
  cursor: context-menu;
  user-select: none;
  position: relative;
  padding-right: 1.05rem !important;
}

th[data-col-menu]::after {
  content: "\F282";                 /* bi-chevron-down */
  font-family: "bootstrap-icons";
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.6rem;
  opacity: 0;
  transition: opacity 0.12s ease-in-out;
  pointer-events: none;
}

th[data-col-menu]:hover::after,
th[data-col-menu].col-menu-open::after {
  opacity: 0.55;
}

th[data-col-menu].col-menu-open {
  background-color: var(--surface-header);
}

/* Active sort: a tinted header plus an arrow. Pages that sort server-side stamp
   this while rendering; pages that sort in the browser stamp it from JS. */
th[data-col-menu].is-sorted {
  background-color: var(--brand-soft);
  color: var(--brand-hover);
}

.col-sort-arrow {
  margin-left: 0.25rem;
  font-size: 0.7rem;
  color: var(--brand);
}

/* ── The floating menu ──────────────────────────────────────── */
#column-menu {
  position: fixed;
  z-index: 9999;
  display: none;
  min-width: 208px;
  max-width: 300px;
  padding: 0.25rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  color: var(--text);
}

#column-menu .colm-header {
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--neutral-100);
  color: var(--text-muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#column-menu .colm-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

#column-menu .colm-item:hover {
  background: var(--table-row-hover);
}

#column-menu .colm-item.is-active {
  color: var(--brand);
  font-weight: 600;
}

#column-menu .colm-item.is-muted {
  color: var(--text-muted);
}

#column-menu .colm-item .colm-check {
  margin-left: auto;
  color: var(--brand);
}

#column-menu .colm-note {
  padding: 0.3rem 0.75rem 0.45rem;
  color: var(--text-faint);
  font-size: var(--fs-2xs);
  white-space: normal;
}

#column-menu .colm-sep {
  margin: 0.25rem 0;
  border-top: 1px solid var(--neutral-100);
}

/* Touch targets need more room than a mouse does. */
@media (pointer: coarse) {
  #column-menu .colm-item {
    padding: 0.7rem 0.9rem;
    font-size: var(--fs-base);
  }
  th[data-col-menu]::after { opacity: 0.4; }
}
