/* gogridgo advanced-filter addon (issue #133): operator button in the
   filter row, the operator picker menu, and the "wybór z listy" values
   popup. Hand-tuned to the same neutral palette as gogridgo.css — the
   library can't depend on the host's CSS framework. */

/* ── filter cell: button bar above the full-width value box ───────────────
   Two stacked lines inside one table cell (still ONE .gg-filter-row <tr>):
   row 1 = [operator][sort ▲][sort ▼][clear ✕], row 2 = the value box at the
   column's full width. min-width:0 throughout — the cell must never widen
   the column when the filter row opens (layout stability).
   The bar buttons are deliberately LOWER than the value box (~2/3 of its
   height, 1.05rem vs ~1.55rem; Michał, 2026-08-28): the value box is the
   main control, the bar is its accessory. Only heights shrank — the widths
   (and so the @container thresholds below) are unchanged. */

.gg-fcell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 1.9rem; /* the operator button always fits, even in a 1-char column */
  /* Size containment in the inline axis: the filter cell stops contributing
     to the column's min-content width, so a short-data column ("Lp", 1..n)
     is no longer inflated to fit the four-button bar (~98px). The column is
     measured by its header and data, and the bar adapts via @container
     below. overflow:hidden keeps the bar from spilling into the neighbour
     in the narrowest columns — the operator menu, values popup and date
     picker are document-level, so nothing clickable gets clipped. */
  container-type: inline-size;
  overflow: hidden;
}

.gg-fbar {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

/* Narrow columns shed buttons that have another home, cheapest loss first.
   Thresholds come from the bar's real widths: all four ≈ 6.2rem (98px),
   operator + clear ≈ 3.1rem (49px), operator alone 1.55rem.
     ≤ 6.2rem — drop the sort pair: clicking the column header sorts, and the
                ▲▼ indicators stay up there, so it costs the least
     ≤ 3.2rem — drop the clear ✕ too ("Wyczyść filtr" lives in the operator
                menu, one extra click away)
   The operator button never goes: it is the only way into that menu (and
   into „Wybór z listy"). */
@container (max-width: 6.2rem) {
  .gg-fbar .gg-fsort { display: none; }
}
@container (max-width: 3.2rem) {
  .gg-fbar .gg-fclear { display: none; }
}
/* Without container-query support nothing hides, so let the bar show in
   full rather than clip it (pre-2022 browsers keep today's behaviour). */
@supports not (container-type: inline-size) {
  .gg-fcell { overflow: visible; }
}

.gg-fval {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.gg-fcell .gg-filter-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

.gg-fop-btn {
  flex: none;
  min-width: 1.55rem;
  height: 1.05rem;
  padding: 0 0.25rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.62rem;
  line-height: 1;
  color: #374151;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  cursor: pointer;
  white-space: nowrap;
}

.gg-fop-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.gg-filter-list-preview {
  cursor: pointer;
  background: #eef2ff;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Active filter on the column: inverted indigo operator button (matches
   the Zastosuj/list-preview family) + tinted value box(es). Rendered
   server-side (colMeta.FilterActive), so it survives every grid swap. */
.gg-fop-btn-on {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
}

.gg-fop-btn-on:hover {
  background: #4338ca;
  border-color: #4338ca;
}

/* Cell-level active class (the op button and the value box live in separate
   bar/val wrappers now, so a sibling combinator can't reach across). */
.gg-fcell-on .gg-filter-input {
  background: #eef2ff;
}

/* Date-op value boxes are plain text inputs with an ISO placeholder —
   mute it slightly so the RRRR-MM-DD hint reads as a hint, and reserve
   enough width for the full mask (narrow columns were clipping it). */
.gg-fcell .gg-filter-input::placeholder {
  color: #b6bcc6;
  font-size: 0.7rem;
}

.gg-fcell .gg-filter-date {
  /* Full ISO date (10 chars); the native search-cancel ✕ is hidden again
     (the bar has an explicit clear button), so no extra allowance. */
  min-width: 5.5rem;
}

/* Sort toggle pair in the button bar: pressing the inactive direction sorts
   by it (the other pops out); pressing the active one removes the column
   from the sort entirely. The header ▲▼ indicators stay — they still show
   the sort when the filter rows are hidden. */
.gg-fsort {
  flex: none;
  min-width: 1.4rem;
  height: 1.05rem;
  padding: 0 0.15rem;
  font-size: 0.55rem;
  line-height: 1;
  color: #6b7280;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  cursor: pointer;
}

.gg-fsort:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.gg-fsort-on {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
}

.gg-fsort-on:hover {
  background: #4338ca;
  border-color: #4338ca;
}

/* Explicit per-column clear ✕ in the button bar (the native in-control
   search-cancel is hidden — see gogridgo.css — so this is THE clear
   affordance; disabled/grey when the column has no active filter). */
/* An ERASER, not a ✕ (Michał): next to a value box a ✕ reads as "close" or
   "delete the row", while a rubber says "wipe what is written here" — which
   is exactly what the button does. Same footprint as before, so the
   container-query thresholds that hide it in narrow columns still hold. */
.gg-fclear {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.05rem;
  min-width: 1.4rem;
  padding: 0 0.15rem;
  font-size: 0.72rem;
  line-height: 1;
  color: #6b7280;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  cursor: pointer;
}

.gg-fclear svg { width: 0.7rem; height: 0.7rem; display: block; }

.gg-fclear:hover {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fca5a5;
}

.gg-fclear:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* 📅 — summons the native calendar for the adjacent date box. */
.gg-fpick {
  flex: none;
  height: 1.55rem;
  min-width: 1.5rem;
  padding: 0 0.15rem;
  font-size: 0.78rem;
  line-height: 1;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  cursor: pointer;
}

.gg-fpick:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

/* Hidden native input whose showPicker() provides the calendar popup —
   parked at the button's coordinates so the popup opens there. */
.gg-fpick-proxy {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: 0;
  padding: 0;
}

/* ── operator picker menu ─────────────────────────────────────────────── */

.gg-fop-menu {
  position: fixed;
  z-index: 1000;
  display: none;
  min-width: 12rem;
  max-height: 70vh;
  overflow: auto;
  padding: 0.25rem;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.4rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.gg-fop-menu.gg-open {
  display: block;
}

.gg-fop-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.22rem 0.5rem;
  font-size: 0.78rem;
  text-align: left;
  color: #1f2937;
  background: none;
  border: 0;
  border-radius: 0.25rem;
  cursor: pointer;
  white-space: nowrap;
}

.gg-fop-item:hover {
  background: #eef2ff;
}

.gg-fop-item-cur {
  background: #e0e7ff;
}

.gg-fop-glyph {
  min-width: 2rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  text-align: center;
  color: #4b5563;
}

.gg-fop-sep {
  height: 1px;
  margin: 0.25rem 0.3rem;
  background: #e5e7eb;
}

.gg-fop-clear:not([disabled]) {
  color: #b91c1c;
}

.gg-fop-clear:not([disabled]) .gg-fop-glyph {
  color: #b91c1c;
}

.gg-fop-clear[disabled] {
  color: #9ca3af;
  cursor: default;
}

.gg-fop-clear[disabled]:hover {
  background: none;
}

/* ── values popup ─────────────────────────────────────────────────────── */

.gg-vals-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  background: rgba(0, 0, 0, 0.12);
}

.gg-vals-backdrop.gg-open {
  display: block;
}

.gg-vals-pop {
  position: fixed;
  z-index: 1001;
  display: none;
  flex-direction: column;
  width: 21rem;
  min-width: 15rem;
  min-height: 12rem;
  max-width: 90vw;
  max-height: 80vh;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  resize: both;
  overflow: hidden; /* inner list scrolls; resize handle stays usable */
}

.gg-vals-pop.gg-open {
  display: flex;
}

.gg-vals-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem 0.35rem;
  border-bottom: 1px solid #e5e7eb;
}

/* Close ✕ in the header replaces the old "Anuluj" in the footer: the
   footer is for the two DECISIONS (clear, apply), and a cancel button next
   to them reads like a third one. */
.gg-vals-close {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 0.25rem;
  background: transparent;
  color: #6b7280;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

.gg-vals-close:hover {
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #111827;
}

/* <puste> is not a value the data contains — say so typographically. */
.gg-vals-blank .gg-vals-label {
  font-style: italic;
  color: #4b5563;
}

.gg-vals-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gg-vals-count {
  flex: none;
  font-size: 0.7rem;
  color: #6b7280;
}

.gg-vals-search {
  margin: 0.4rem 0.65rem 0.2rem;
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.3rem;
}

/* "Ukryj niewystępujące" toggle — shown only when the fragment contains
   grayed-out (filtered-away) entries. */
.gg-vals-hideoff {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.1rem 0.65rem 0.2rem;
  font-size: 0.7rem;
  color: #6b7280;
  cursor: pointer;
}

/* Entry with zero occurrences under the other columns' active filters. */
.gg-vals-off {
  opacity: 0.45;
}

.gg-vals-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 0.15rem 0.4rem 0.3rem;
}

.gg-vals-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.14rem 0.3rem;
  font-size: 0.76rem;
  color: #1f2937;
  border-radius: 0.25rem;
  cursor: pointer;
}

.gg-vals-item:hover {
  background: #f3f4f6;
}

.gg-vals-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gg-vals-n {
  flex: none;
  font-size: 0.68rem;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
}

.gg-vals-notice {
  margin: 0.25rem 0.35rem;
  padding: 0.3rem 0.45rem;
  font-size: 0.7rem;
  color: #92400e;
  background: #fef3c7;
  border-radius: 0.3rem;
}

.gg-vals-empty,
.gg-vals-spin {
  padding: 0.75rem 0.5rem;
  font-size: 0.75rem;
  color: #6b7280;
}

.gg-vals-foot {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.65rem;
  border-top: 1px solid #e5e7eb;
}

.gg-vals-foot-gap {
  flex: 1 1 auto;
}

.gg-vals-foot button {
  padding: 0.22rem 0.7rem;
  font-size: 0.75rem;
  color: #1f2937;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.3rem;
  cursor: pointer;
}

.gg-vals-foot button:hover {
  background: #f3f4f6;
}

.gg-vals-foot .gg-vals-apply {
  color: #fff;
  background: #4f46e5;
  border-color: #4f46e5;
}

.gg-vals-foot .gg-vals-apply:hover {
  background: #4338ca;
}
