/*
 * Advanced filter toolbar — the shared advanced-filter strip and the
 * `.multi-filter` multi-select component that lives inside it (ISH-261).
 *
 * Before this file, the toolbar pattern existed as three hand-copied blocks in
 * brokers.html, analytics.html and map.html, each with its own inline <style>
 * copy of the same ~180 lines. ISH-261 needed a fourth consumer (the Sales
 * Pipeline board), so the block was factored out here rather than pasted again
 * — the same move css/stage-colors.css made for the stage palette.
 *
 * The values are brokers.html's, which is the canonical look the other pages
 * were copied from. One intentional difference: `.filter-clear-btn` sets
 * `align-self: center` here, because brokers.html's `flex-end` base was already
 * overridden to center by an inline style on the element itself — center is what
 * that page actually renders, so it is what the shared file declares.
 *
 * Consumers today: sales-pipeline.html, sales-pipeline-report.html (ISH-497 —
 * its geography scope bar's Region/Market/Submarket filters). brokers.html,
 * analytics.html and map.html still carry their own copies; migrating them is
 * deliberately left out of ISH-261 (three heavily-used pages, no behavior
 * change to show for it) and tracked as ISH-444. When you migrate one, delete
 * its inline block rather than leaving both — a page linking this file *and*
 * declaring `.mf-trigger` locally is how the pre-ISH-353 stage palette drifted.
 *
 * Depends on the page's own :root tokens: --red, --border, --border-light,
 * --page-bg, --text, --text-secondary, --text-label, --radius. Every page in
 * this app declares all of them.
 *
 * The markup contract this styles (see sales-pipeline.html for a full example):
 *
 *   .filter-btn                 toggles [hidden] on .filter-strip
 *   .filter-clear-btn           resets every filter at once
 *   .filter-strip > .filter-row.row-spread > .filter-group
 *     label + .multi-filter
 *       .mf-trigger             shows placeholder, or .mf-trigger-chip per value
 *       .mf-dropdown[hidden]    .mf-search + .mf-list > .mf-option / .mf-empty
 *
 * js/shared.js's createMultiFilter() drives that markup — it owns the classes
 * `has-value`, `selected`, `mf-empty` and the `aria-expanded` toggle, so don't
 * rename them here without changing it too.
 */

/* Icon button that expands/collapses the strip. Square to match the 42px
   search input it sits beside in .search-row. */
.filter-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition:
    border-color 0.15s,
    background 0.15s,
    color 0.15s;
}

.filter-btn:hover {
  border-color: #aaa;
  color: var(--text);
}

.filter-btn.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.filter-clear-btn {
  align-self: center;
  height: 32px;
  padding: 0 0.5rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  color: #aaa;
  cursor: pointer;
  transition: color 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.filter-clear-btn:hover {
  color: var(--text);
}

/* Filter strip — no border of its own; it lives inside the white toolbar card
   and separates itself with a top rule. */
.filter-strip {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-top: 1px solid var(--border-light);
  padding-top: 1.25rem;
  margin-top: 0.5rem;
}

.filter-strip[hidden] {
  display: none;
}

.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
}

.filter-row.row-spread {
  justify-content: space-between;
}

.filter-row.row-spread .filter-group {
  flex: 1;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 130px;
  flex: 1;
}

.filter-group label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Multi-select filter component */
.multi-filter {
  position: relative;
}

.mf-trigger {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  min-height: 30px;
  padding: 0.3rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  background: #fff;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
  box-sizing: border-box;
}

.mf-trigger:hover {
  border-color: #999;
  color: var(--text);
}

.mf-trigger.has-value {
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
}

.mf-chevron {
  flex-shrink: 0;
  margin-left: auto;
}

.mf-trigger[aria-expanded="true"] .mf-chevron {
  transform: rotate(180deg);
}

.mf-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 1010;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  min-width: 240px;
  max-width: 320px;
}

.mf-dropdown[hidden] {
  display: none;
}

.mf-search {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.75rem;
  border: none;
  border-bottom: 1px solid var(--border-light);
  font: inherit;
  font-size: 0.8125rem;
  color: var(--text);
  outline: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.mf-search::placeholder {
  color: var(--text-label);
}

.mf-list {
  max-height: 200px;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.mf-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}

.mf-option:hover {
  background: var(--page-bg);
}

.mf-option.selected {
  font-weight: 600;
  color: var(--red);
}

.mf-option .mf-check {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #fff;
  transition:
    background 0.1s,
    border-color 0.1s;
}

.mf-option.selected .mf-check {
  background: var(--red);
  border-color: var(--red);
}

.mf-option.selected .mf-check::after {
  content: "";
  display: block;
  width: 4px;
  height: 7px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.mf-empty {
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-label);
  font-style: italic;
}

/* Selected values render as chips inside the trigger itself, so a collapsed
   filter still shows what it is filtering on. */
.mf-trigger-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.55rem;
  background: rgba(166, 38, 38, 0.15);
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--red);
  white-space: nowrap;
}

.mf-trigger-chip-remove {
  border: none;
  background: none;
  color: var(--red);
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  opacity: 0.7;
}

.mf-trigger-chip-remove:hover {
  opacity: 1;
}

/*
 * View switcher (ISH-457) — the Cards / Kanban / Table button group.
 *
 * Filed here rather than in a new file of its own, which makes this stylesheet's
 * name slightly narrower than its contents: the switcher sits in the page header
 * beside the toolbar, not inside the filter strip. Thirty lines did not justify a
 * fifth stylesheet, and every page that wants a view switcher already wants the
 * filter strip. Read the file as "shared list-page chrome".
 *
 * The values are brokers.html's inline copy verbatim, which is the canonical look.
 * **brokers.html is now the duplicate**, not the source — it still carries its own
 * inline block because it does not load this stylesheet at all yet. Deleting that
 * block belongs to ISH-444 along with its `.multi-filter`/`.filter-strip` copies;
 * do not migrate it piecemeal from here, or the page ends up half-served by two
 * files. The 42px height is load-bearing: it lines the group up with `.search-row`
 * controls and the count card, which are all explicitly 42px.
 */
.view-toggle-wrap {
  display: inline-flex;
  align-items: center;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
  height: 42px;
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-label);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background-color 0.15s,
    color 0.15s;
}

.view-toggle-btn:hover {
  color: var(--text);
}

.view-toggle-btn.active {
  background: var(--red);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/*
 * Has Flags / No Flags filter (ISH-457) — a mutually-exclusive pair, not a
 * `.multi-filter`. Two options with no search and no multi-select would be a
 * dropdown you open to see two words, so they render as inline chips instead.
 * Clicking the active one clears the filter, matching brokers.html's flag cards.
 */
.flag-toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 38px;
}

.flag-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 34px;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: #ffffff;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.flag-toggle-btn:hover {
  border-color: #bbbbbb;
  color: var(--text);
}

.flag-toggle-btn[aria-pressed="true"] {
  background: var(--red);
  border-color: var(--red);
  color: #ffffff;
}

@media (max-width: 700px) {
  .filter-row.row-spread {
    flex-wrap: wrap;
  }

  .filter-row.row-spread .filter-group {
    flex-basis: 100%;
  }
}
