/* ============================================================
   FT-FILTER-* (Phase 4)
   ------------------------------------------------------------
   Chip-and-facet filter bar shared by Devices + Customers pages.
   All rules namespaced `.ft-filter-*` to avoid colliding with
   `.tab-btn` / `.toolbar-tabs` / `.email-tag` / `.modal-overlay`.

   Wave 2 (Plan 04-03): chip bar + facet button + active chip +
   popover + mobile responsive + sr-only. Views dropdown + Manage
   Views modal rules land in Wave 3 (Plan 04-04).

   z-index map:
     .ft-drop-overlay        150 (Phase 3)
     .ft-filter-popover      180 (Phase 4 — locked by UI-SPEC)
     .modal-overlay          200 (existing)
     .cmd-backdrop           250 (existing)
   ============================================================ */

/* ---- chip bar container (UI-SPEC Component 1) ---- */
.ft-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}
.ft-filter-bar-mount {
  display: contents; /* the mount container itself has no box — children participate in .toolbar layout */
}
.ft-filter-facet-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.ft-filter-views-slot {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
}

/* ---- facet button (UI-SPEC Component 2) ---- */
.ft-filter-facet {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.ft-filter-facet:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}
.ft-filter-facet:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(42,171,224,0.15);
  border-color: var(--accent);
}
.ft-filter-facet-open,
.ft-filter-facet[aria-expanded="true"] {
  background: var(--accent-light);
  border-color: var(--accent-border);
  color: var(--accent-dark);
}
.ft-filter-facet[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}
.ft-filter-chevron {
  opacity: 0.6;
  font-size: 12px;
  line-height: 1;
}

/* ---- active chip (UI-SPEC Component 3) ---- */
.ft-filter-chip {
  height: 32px;
  border-radius: 999px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  transition: all var(--transition);
}
.ft-filter-chip-body {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  outline: none;
}
.ft-filter-chip-body:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(42,171,224,0.15);
}
.ft-filter-chip:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}
.ft-filter-chip-remove {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: none;
  background: none;
  color: rgba(255,255,255,0.85);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all var(--transition);
}
.ft-filter-chip-remove:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.ft-filter-chip-remove:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(42,171,224,0.15);
}

/* ---- popover (UI-SPEC Component 4) ---- */
.ft-filter-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  max-width: 360px;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 180;
  animation: ftFilterPopoverIn 120ms ease-out;
}
.ft-filter-popover-flip-right {
  left: auto;
  right: 0;
}
.ft-filter-popover-flip-up {
  top: auto;
  bottom: calc(100% + 6px);
}
@keyframes ftFilterPopoverIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ft-filter-popover-search {
  position: sticky;
  top: 0;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.ft-filter-popover-search input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.ft-filter-popover-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42,171,224,0.15);
}
.ft-filter-popover-list {
  padding: 4px 0;
}
.ft-filter-option {
  height: 32px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
  white-space: nowrap;
}
.ft-filter-option input[type="checkbox"],
.ft-filter-option input[type="radio"] {
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}
.ft-filter-option-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ft-filter-option-count {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-hint);
  font-variant-numeric: tabular-nums;
}
.ft-filter-option:hover {
  background: var(--bg);
}
.ft-filter-option:focus-visible {
  outline: 1px solid var(--accent-border);
  outline-offset: -1px;
  background: var(--accent-light);
}
.ft-filter-option-zero {
  opacity: 0.5;
}
.ft-filter-popover-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}
.ft-filter-popover-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  gap: 8px;
}
.ft-filter-popover-clear {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 8px;
}
.ft-filter-popover-clear:hover {
  color: var(--text);
}
.ft-filter-custom-range {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ft-filter-custom-range label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.ft-filter-custom-range input[type="date"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  flex: 1;
}

/* ---- screen-reader-only utility (UI-SPEC §ARIA contract) ---- */
.ft-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

/* ---- responsive: mobile / iPad narrow (UI-SPEC §Dependency Notes) ---- */
@media (max-width: 768px) {
  .ft-filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
    scrollbar-width: thin;
  }
  .ft-filter-views-slot {
    margin-left: 0;
    flex-shrink: 0;
  }
  .ft-filter-facet,
  .ft-filter-chip {
    min-height: 44px; /* UI-SPEC touch target */
  }
}

/* ============================================================
   Views dropdown + Manage Views modal (Phase 4 Plan 04)
   ------------------------------------------------------------
   UI-SPEC Components 5 and 6. Manage modal chrome reuses
   existing .modal-overlay / .modal / .modal-header / .modal-close
   (styles.css:354-377). This block adds only the Phase-4 specific
   shape overrides and the views-dropdown menu styling.
   ============================================================ */

/* Views dropdown button — shape identical to .ft-filter-facet */
.ft-filter-views {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ft-filter-views:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}
.ft-filter-views:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(42,171,224,0.15);
  border-color: var(--accent);
}
.ft-filter-views[aria-expanded="true"] {
  background: var(--accent-light);
  border-color: var(--accent-border);
  color: var(--accent-dark);
}

/* Views dropdown menu */
.ft-filter-views-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: auto;
  min-width: 240px;
  max-width: 280px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 180;
  animation: ftFilterPopoverIn 120ms ease-out;
}
.ft-filter-views-menu-flip-right {
  right: auto;
  left: 0;
}
.ft-filter-views-header {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-hint);
  text-transform: uppercase;
}
.ft-filter-views-row {
  width: 100%;
  display: grid;
  grid-template-columns: 16px 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: none;
  border: none;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  height: 32px;
}
.ft-filter-views-row:hover {
  background: var(--bg);
}
.ft-filter-views-row:focus-visible {
  outline: 1px solid var(--accent-border);
  outline-offset: -1px;
  background: var(--accent-light);
}
.ft-filter-views-tick {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.ft-filter-views-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ft-filter-views-empty {
  padding: 16px 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}
.ft-filter-views-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}
.ft-filter-views-action {
  width: 100%;
  display: block;
  padding: 6px 12px;
  background: none;
  border: none;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  height: 32px;
  line-height: 20px;
}
.ft-filter-views-action:hover:not([disabled]) {
  background: var(--bg);
}
.ft-filter-views-action:focus-visible {
  outline: 1px solid var(--accent-border);
  outline-offset: -1px;
  background: var(--accent-light);
}
.ft-filter-views-action[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.ft-filter-views-save-input {
  padding: 4px 12px;
}
.ft-filter-views-save-input input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.ft-filter-views-save-input input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42,171,224,0.15);
}

/* Manage Views modal — overrides default .modal max-width */
.ft-filter-views-modal {
  max-width: 480px;
}
.ft-filter-views-modal-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 60vh;
  overflow-y: auto;
}
.ft-filter-views-modal-row {
  display: grid;
  grid-template-columns: 32px 32px 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.ft-filter-views-modal-row:last-child {
  border-bottom: none;
}
.ft-filter-views-modal-name {
  font-size: 14px;
  color: var(--text);
  padding: 4px 6px;
  border-radius: var(--radius);
  cursor: text;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ft-filter-views-modal-name:hover {
  background: var(--bg);
}
.ft-filter-views-modal-rename {
  padding: 4px 6px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
  width: 100%;
}
.ft-filter-views-modal-rename:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(42,171,224,0.15);
}
.ft-filter-views-modal-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}
