/* Leads Filter (Build Q): the one Filter button, its popover and the active chips bar.
   components/lead-filter.js; look: state/lanes/leadsprio-design.md 4. Class prefix lfil-. Tokens only. */

/* ---- Trigger ---- */
.lfil-btn.is-filtered { border-color: var(--border-focus); color: var(--blue); background: var(--chip-active-bg); }
.lfil-btn.is-filtered .ic, .lfil-btn.is-filtered svg { color: var(--blue); }
.lfil-btn.is-open { border-color: var(--border-focus); }

/* ---- Popover ---- */
.lfil-pop { padding: 0; border-radius: var(--menu-radius); box-shadow: var(--menu-shadow); }
.lfil { width: 360px; max-width: calc(100vw - 32px); display: flex; flex-direction: column; }
.lfil-groups {
  max-height: min(64vh, 560px); overflow-y: auto; padding: var(--sp-5) var(--sp-6) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-6);
}
.lfil-group { display: flex; flex-direction: column; gap: var(--sp-3); }
.lfil-cap { font-size: var(--fs-sm); line-height: var(--lh-sm); font-weight: var(--fw-semibold); color: var(--text-2); }
.lfil-chips { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.lfil-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2); height: var(--control-h); padding: 0 var(--sp-5);
  border: 1px solid transparent; border-radius: var(--r-pill); background: var(--chip-bg); color: var(--text);
  font: inherit; font-size: var(--fs-md); cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.lfil-chip:hover { background: var(--bg-hover); border-color: var(--border); }
.lfil-chip:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.lfil-chip.is-on { background: var(--chip-active-bg); color: var(--chip-active-text); border-color: var(--border-focus); }
.lfil-chip-tick { display: none; }
.lfil-chip-tick svg { width: 14px; height: 14px; display: block; }
.lfil-chip.is-on .lfil-chip-tick { display: inline-flex; }
.lfil-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--text-muted); }
.lfil-dot.quality-hot { background: var(--quality-hot); }
.lfil-dot.quality-medium { background: var(--quality-medium); }
.lfil-dot.quality-unsure { background: var(--quality-unsure); }
.lfil-dot.quality-low { background: var(--quality-low); }
.lfil-dot.quality-not_good { background: var(--quality-not-good); }

/* Case type: a select-like button that opens its checkbox list in place. */
.lfil-case-btn {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); width: 100%;
  height: var(--control-h); padding: 0 var(--sp-4) 0 var(--sp-5); border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-surface); color: var(--text-2); font: inherit; text-align: left; cursor: pointer;
}
.lfil-case-btn.is-on { color: var(--text); border-color: var(--border-focus); }
.lfil-case-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 0; }
.lfil-case-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lfil-case-caret svg { width: 16px; height: 16px; display: block; transition: transform var(--t-fast) var(--ease); }
.lfil-case-btn[aria-expanded="true"] .lfil-case-caret svg { transform: rotate(180deg); }

/* Checkbox rows (case types, labels): the shared 16px checkbox on the left. */
.lfil-checks { display: flex; flex-direction: column; max-height: 220px; overflow-y: auto; margin: 0 calc(-1 * var(--sp-4)); }
.lfil-check {
  display: flex; align-items: center; gap: var(--sp-4); width: 100%; min-height: var(--control-h); padding: 0 var(--sp-4);
  border: 0; border-radius: var(--r-sm); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.lfil-check[hidden] { display: none; }
.lfil-check:hover { background: var(--bg-hover); }
.lfil-check:focus-visible { outline: none; background: var(--menu-hover-bg); color: var(--menu-hover-text); }
.lfil-check-name { flex: 1; min-width: 0; }
.lfil-label-pill { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Labels sit third (right after Quality) as a compact wrapping row of chips: each keeps its 16px checkbox + pill,
   3 rows and a peek of the 4th (the peek hints that it scrolls), so the popover stays short and Labels shows without scrolling. */
.lfil-checks.lfil-labels {
  flex-direction: row; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); max-height: 120px; margin: 0; align-content: flex-start;
}
.lfil-labels .lfil-check { width: auto; max-width: 100%; min-height: 0; height: var(--control-h); gap: var(--sp-3); padding: 0 var(--sp-3) 0 var(--sp-2); }
.lfil-labels .lfil-empty { flex-basis: 100%; padding: var(--sp-2) 0; }
.lfil-box {
  display: grid; place-items: center; width: 16px; height: 16px; flex: none; border: 1px solid var(--border-strong);
  border-radius: 3px; background: var(--bg-surface); color: transparent;
}
.lfil-box .ic, .lfil-box svg { width: 12px; height: 12px; display: block; }
.lfil-check.is-checked .lfil-box { border-color: var(--blue-bright); background: var(--blue-bright); color: var(--text-inverse); }
.lfil-search {
  display: flex; align-items: center; gap: var(--sp-3); height: var(--control-h); padding: 0 var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-surface); cursor: text;
}
.lfil-search:focus-within { border-color: var(--border-focus); }
.lfil-search-ic, .lfil-search-ic svg { width: 16px; height: 16px; display: block; color: var(--text-2); flex: none; }
.lfil-search-input.input { flex: 1; min-width: 0; height: 30px; padding: 0; border: 0; background: none; }
.lfil-empty { padding: var(--sp-3) var(--sp-4); color: var(--text-2); font-size: var(--fs-sm); }
.lfil-empty[hidden] { display: none; }

.lfil-foot {
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border);
}

/* ---- Active chips bar (under the toolbar, only while filtering) ---- */
.lfil-bar { display: flex; align-items: center; gap: var(--sp-4); min-height: 40px; padding: var(--sp-3) 0; flex-wrap: wrap; }
.lfil-bar[hidden] { display: none; }
.lfil-bar-chips { display: flex; flex-wrap: wrap; gap: var(--sp-3); min-width: 0; }
.lfil-fchip {
  display: inline-flex; align-items: center; gap: var(--sp-2); height: 24px; max-width: 320px; padding: 0 var(--sp-1) 0 var(--sp-4);
  border-radius: var(--r-pill); background: var(--chip-active-bg); color: var(--chip-active-text);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold);
}
.lfil-fchip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lfil-fchip-x {
  display: grid; place-items: center; width: 20px; height: 20px; flex: none; padding: 0; border: 0; border-radius: 50%;
  background: none; color: inherit; cursor: pointer;
}
.lfil-fchip-x svg { width: 12px; height: 12px; display: block; }
.lfil-fchip-x:hover { background: color-mix(in srgb, var(--chip-active-text) 14%, transparent); }
.lfil-fchip-x:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 0; }
.lfil-bar-clear {
  height: 24px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: none; color: var(--link);
  font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer;
}
.lfil-bar-clear:hover { background: var(--bg-hover); }
.lfil-bar-clear:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 0; }

/* ---- Phone: the popover becomes a full-width sheet with a 16px gutter ---- */
@media (max-width: 640px) {
  .popover.lfil-pop { left: 16px !important; right: 16px; width: auto; }
  .lfil { width: 100%; max-width: none; }
  .lfil-groups { max-height: 60vh; }
  .lfil-fchip { max-width: calc(100vw - 64px); }
}
@media (prefers-reduced-motion: reduce) {
  .lfil-chip, .lfil-case-caret svg { transition: none; }
}
