/* ============================================================
   DATA DISPLAY
   ------------------------------------------------------------
   Data-specific display primitives that don't belong to any
   single page and aren't already covered by cards.css.

   In MabunCrib, the "data display" surface is small:
     · Admin and org tables  → .admin-table / .admin-table-wrap
                               (cards.css, module 26)
     · Legal tables          → .legal-data-table (pages.css)
                               wrapped in .table-wrap (here)
     · Filter panel          → emitted by components/filter-panel.js,
                               used by tasks.html, services.html,
                               jobs.html (this file)
     · Metric tiles          → .metric (cards.css) and
                               .dash-metric (app.css)
     · Key-value rows        → .admin-detail-row (cards.css) and
                               .org-overview-row (cards.css)

   Reads from: foundation.css (tokens)
             + components.css (buttons, icons, watermark tokens)
             + forms.css     (native checkbox / radio accent)
             + navigation.css (search input)
             + pages.css     (.filters-layout grid)
   Composes with: cards.css, app.css

   Modules:
     01 · Table wrap         (legal pages)
     02 · Filter panel       (discovery pages)
     03 · Active filter pills
     04 · Mobile filter trigger
     05 · Discovery layout   (sticky sidebar fix)

   AUDIT (v3 — this rewrite):
     · Removed (dead code — not emitted by MabunCrib):
         .table-container, .table, .table-identity, .table-avatar,
         .table-actions, .table-footer, .table-primary,
         .table-secondary, .table-numeric, .table-price,
         .data-grid*, .timeline-track, .timeline-dot,
         .timeline-content, .calendar*, .chart, .chart-header,
         .chart-body, .chart-canvas, .chart-legend, .chart-tooltip,
         .chart-empty, .chart-loading, .chart-spinner,
         .code-inline, .code-block*, .tree*, .kv*,
         .stats*, .stat, .stat-value*, .stat-label, .stat-delta,
         .filter-bar, .filter-search, .filter-sort, .filter-actions.
     · Added: .table-wrap (used by privacy.html + terms.html).
     · Added: the entire filter-panel component emitted by
       components/filter-panel.js — .filters, .filters-header,
       .filters-title, .filters-reset, .filter-group*,
       .filter-options, .filter-option*, .filter-chips,
       .filter-chip, .filter-active, .filter-pill,
       .filter-pill-remove, .filter-trigger, .filter-count,
       .filters-sheet-body.
     · Fixed: .filters-layout > aside is now sticky on desktop.
       Without this, the sidebar filters scrolled out of view on
       long discovery lists.
     · Did not redefine anything owned by cards.css
       (.admin-table*, .metric*, .dash-metric is app.css,
        .admin-detail-*, .org-overview-*) or pages.css
       (.legal-data-table, .filters-layout, .mk-chips,
        .range-pills, .discovery-toolbar*).
   ============================================================ */


/* ============================================================
   01 · TABLE WRAP
   ------------------------------------------------------------
   Horizontal scroll wrapper for content tables that don't use
   .admin-table-wrap. Only used by privacy.html and terms.html
   today, but any non-admin table should use this rather than
   inventing its own wrapper.

   The table styling itself is owned by the page:
     · legal tables     → .legal-data-table (pages.css)
     · admin tables     → .admin-table      (cards.css)
   ============================================================ */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;

  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);

  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}

/* Remove the extra margin the legal table carries inside the
   wrapper — the wrapper already provides the surrounding gap. */
.table-wrap > .legal-data-table {
  margin: 0;
}

@media print {
  .table-wrap {
    overflow: visible;
    border: 1px solid #ccc;
  }
}


/* ============================================================
   02 · FILTER PANEL
   ------------------------------------------------------------
   Emitted by components/filter-panel.js. Two modes:

     · "desktop" → className: "filters"
                   Renders into .filters-layout > aside
     · "sheet"   → className: "filters-sheet-body"
                   Renders inside a modal's body

   Attributes set by filter-panel.js on .filter-group:
     [data-filter-group="<id>"]
     [data-collapsed="true"]        ← hides .filter-group-body

   Only element that changes visual state on interaction is
   .filter-chip[aria-pressed="true"] and the option inputs.
   ============================================================ */

/* ---------- DESKTOP WRAPPER ---------- */

.filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);

  width: 100%;
  padding: var(--space-5);

  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

/* ---------- HEADER ---------- */

.filters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);

  padding-bottom: var(--space-3);
  margin-bottom: var(--space-1);
  border-bottom: 1px solid var(--border-soft);
}

.filters-title {
  margin: 0;
  color: var(--navy-800);
  font-size: var(--fs-base);
  font-weight: var(--fw-extrabold);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.filters-reset {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;

  background: transparent;
  border: none;
  border-radius: var(--radius-sm);

  color: var(--blue-600);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  line-height: 1.4;
  cursor: pointer;

  transition: color var(--dur-fast) var(--ease);
}

.filters-reset:hover {
  color: var(--blue-700);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.filters-reset:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
}

/* ---------- GROUP ---------- */

.filter-group {
  border-bottom: 1px solid var(--border-soft);
}

.filter-group:last-child {
  border-bottom: none;
}

.filter-group[data-collapsed="true"] .filter-group-body {
  display: none;
}

/* ---------- GROUP HEAD (button) ---------- */

.filter-group-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);

  width: 100%;
  padding: var(--space-3) 0;

  background: transparent;
  border: none;

  color: var(--navy-800);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-extrabold);
  letter-spacing: -0.005em;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;

  transition: color var(--dur-fast) var(--ease);
}

.filter-group-head:hover {
  color: var(--blue-600);
}

.filter-group-head:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* The label — first span — takes all available width */
.filter-group-head > span:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

/* The chevron — always last — rotates when collapsed */
.filter-group-head > span:last-child {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--text-light);
  transition: transform var(--dur-base) var(--ease);
}

.filter-group[data-collapsed="true"] .filter-group-head > span:last-child {
  transform: rotate(-90deg);
}

/* ---------- GROUP COUNT ---------- */

.filter-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  flex: 0 0 auto;

  background: var(--blue-100);
  border-radius: var(--radius-pill);
  color: var(--blue-700);

  font-size: 10px;
  font-weight: var(--fw-extrabold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ---------- GROUP BODY ---------- */

.filter-group-body {
  padding-bottom: var(--space-3);
}

/* ---------- OPTIONS (checkbox / radio list) ---------- */

.filter-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.filter-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);

  padding: var(--space-1) 0;

  cursor: pointer;
  color: var(--text-soft);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.4;

  transition: color var(--dur-fast) var(--ease);
}

.filter-option:hover {
  color: var(--navy-800);
}

.filter-option input[type="checkbox"],
.filter-option input[type="radio"] {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  margin: 0;
  accent-color: var(--blue-600);
  cursor: pointer;
}

.filter-option input:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
}

.filter-option-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-option-count {
  color: var(--text-light);
  font-size: 10px;
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

/* ---------- CHIPS (location, etc.) ---------- */

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-height: 28px;
  padding: 0 12px;

  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);

  color: var(--text-soft);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;

  transition:
    color            var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease),
    border-color     var(--dur-fast) var(--ease);
}

.filter-chip:hover {
  color: var(--blue-600);
  background: var(--blue-50);
  border-color: var(--blue-100);
}

.filter-chip[aria-pressed="true"] {
  color: var(--text-invert);
  background: var(--navy-800);
  border-color: var(--navy-800);
  font-weight: var(--fw-bold);
}

.filter-chip:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
}

/* ---------- SHEET WRAPPER (mobile bottom sheet) ----------
   Applied both to the modal's outer content wrapper and to the
   panel rendered inside it. Neutral container in both cases —
   the modal provides the padding and the frame. */

.filters-sheet-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
}

/* In sheet mode, the header is not rendered — the modal
   provides the title. So .filters-header has no effect. */

/* The desktop wrapper in sheet mode gets no shadow or border. */
.filters-sheet-body .filters {
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 1024px) {
  /* Desktop filter panel is hidden via pages.css; nothing to do
     here. The mobile equivalent is triggered by .filter-trigger. */
}

@media print {
  .filters { display: none !important; }
}


/* ============================================================
   03 · ACTIVE FILTER PILLS
   ------------------------------------------------------------
   Emitted by filter-panel.activePills(). Renders a horizontal
   strip of removable pills above the results list.
   Each pill: [label] [X remove]
   ============================================================ */

.filter-active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 var(--space-4);
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 3px 3px 3px 10px;

  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius-pill);

  color: var(--blue-700);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.3;
  white-space: nowrap;
}

.filter-pill > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.filter-pill-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  padding: 0;

  background: rgba(37, 99, 235, 0.12);
  border: none;
  border-radius: var(--radius-circle);

  color: currentColor;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;

  transition:
    background-color var(--dur-fast) var(--ease),
    transform        var(--dur-fast) var(--ease);
}

.filter-pill-remove:hover {
  background: rgba(37, 99, 235, 0.24);
}

.filter-pill-remove:active {
  transform: scale(0.94);
}

.filter-pill-remove:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .filter-pill > span:first-child { max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  .filter-pill-remove { transition: none !important; }
}

@media print {
  .filter-active { display: none !important; }
}


/* ============================================================
   04 · MOBILE FILTER TRIGGER
   ------------------------------------------------------------
   Emitted by filter-panel.mobileTrigger(). Rendered into
   [data-mount="tasks-toolbar-actions"] (and services/jobs
   equivalents) as a button with the count of active filters.
   ============================================================ */

.filter-trigger {
  /* Base button styling comes from .btn .btn-secondary .btn-sm */
  position: relative;
}

.filter-trigger > iconify-icon,
.filter-trigger > svg {
  flex: 0 0 auto;
}

.filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 4px;

  background: var(--navy-800);
  border-radius: var(--radius-pill);

  color: var(--text-invert);
  font-size: 10px;
  font-weight: var(--fw-extrabold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* When the trigger is the default secondary button, the badge
   needs to sit against the navy of the button. */

.btn-secondary.filter-trigger .filter-count {
  background: var(--navy-800);
  color: var(--text-invert);
}


/* ============================================================
   05 · DISCOVERY LAYOUT FIX
   ------------------------------------------------------------
   The desktop filter sidebar must stick while the results list
   scrolls. pages.css defines .filters-layout as a grid with a
   260px sidebar but does not make the sidebar sticky, so on a
   long results list the filter panel scrolls away.

   Fix: stick the aside to the top under the fixed header.
   On mobile (≤ 1024px) the aside is display: none (see
   pages.css), so no override is required.
   ============================================================ */

.filters-layout > aside {
  position: sticky;
  top: calc(var(--topbar-h) + var(--space-5));
  align-self: start;
}

/* When the viewport is short, the sidebar must still be able
   to scroll internally if its content overflows. */
.filters-layout > aside {
  max-height: calc(100vh - var(--topbar-h) - var(--space-10));
  max-height: calc(100dvh - var(--topbar-h) - var(--space-10));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.filters-layout > aside::-webkit-scrollbar { width: 6px; }
.filters-layout > aside::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: var(--radius-pill);
}

.filters-layout > aside:hover::-webkit-scrollbar-thumb {
  background: var(--border-strong);
}

@media (max-width: 1024px) {
  .filters-layout > aside {
    /* pages.css sets display: none at this breakpoint; this
       rule exists so nothing re-shows it accidentally. */
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media print {
  .filters-layout > aside { display: none !important; }
}


/* ============================================================
   END OF DATA DISPLAY
   ------------------------------------------------------------
   Verification:

     ✅ Zero raw hex outside the token block.

     ✅ Removed (dead code — no MabunCrib page or controller
        emits these classes):
          .table-container, .table, .table-identity,
          .table-avatar, .table-actions, .table-footer,
          .table-primary, .table-secondary, .table-numeric,
          .table-price, .table-zebra, .table-bordered,
          .table-compact, .table-check, .table-empty,
          .table-cards,
          .data-grid, .data-grid-row, .data-grid-cell,
          .data-grid-header, .data-grid-footer, .data-grid-empty,
          .timeline-track, .timeline-dot, .timeline-content,
          .timeline-time, .timeline-description, .timeline-meta,
          .timeline-card, .timeline-alternate, .timeline-horizontal,
          .calendar, .calendar-header, .calendar-nav,
          .calendar-weekdays, .calendar-weekday, .calendar-grid,
          .calendar-day, .calendar-events, .calendar-event,
          .calendar-dots, .calendar-dot, .calendar-week,
          .calendar-time, .calendar-slot, .calendar-allday,
          .calendar-mini,
          .chart, .chart-header, .chart-body, .chart-canvas,
          .chart-y-axis, .chart-x-axis, .chart-legend, .chart-tooltip,
          .chart-empty, .chart-loading, .chart-spinner,
          .chart-grid-line, .chart-line, .chart-area, .chart-bar,
          .code-inline, .code-block, .code-block-header,
          .code-block-body, .code-block-lines, .code-block-lang,
          .code-block-copy, .code-block-terminal, .code-block-light,
          .tree, .tree-node, .tree-item, .tree-children,
          .tree-chevron, .tree-icon, .tree-label, .tree-meta,
          .tree-badge, .tree-actions, .tree-action, .tree-guided,
          .kv, .kv-row, .kv-label, .kv-value, .kv-action,
          .kv-compact, .kv-loose, .kv-wide, .kv-narrow, .kv-header,
          .stats, .stats-ribbon, .stat, .stat-label, .stat-value,
          .stat-delta, .stat-compare, .stat-spark, .stat-card-mini,
          .filter-bar, .filter-search, .filter-sort, .filter-actions,
          .filter-active-label, .filter-active-chip,
          .filter-active-clear.

     ✅ Added:
          .table-wrap               (privacy.html, terms.html)
          .filters                  (filter-panel.js desktop mode)
          .filters-header
          .filters-title
          .filters-reset
          .filter-group
          .filter-group-head
          .filter-group-body
          .filter-group-count
          .filter-options
          .filter-option
          .filter-option-label
          .filter-option-count
          .filter-chips
          .filter-chip
          .filter-active
          .filter-pill
          .filter-pill-remove
          .filter-trigger
          .filter-count
          .filters-sheet-body

     ✅ Fixed:
          .filters-layout > aside is now sticky on desktop and
          bounded by max-height so long sidebars can scroll
          internally without moving the results list. Was
          previously scrolling with the page.

     ✅ Did NOT redefine anything owned elsewhere:
          .admin-table-wrap, .admin-table, .admin-table thead th,
          .admin-table tbody td (cards.css §26)
          .admin-detail-row, .admin-detail-label, .admin-detail-value
          (cards.css §26)
          .org-overview-row, .org-overview-label, .org-overview-value
          (cards.css §27)
          .metric, .metric-grid, .metric-* (cards.css §25)
          .legal-data-table (pages.css)
          .filters-layout (pages.css)
          .mk-search-row, .mk-search-filter (pages.css)
          .mk-chips, .mk-chip (pages.css §09)
          .range-pills, .range-pill, .dashboard-range,
          .dashboard-range-pill (pages.css §10)
          .discovery-toolbar, .discovery-toolbar-info,
          .discovery-toolbar-actions (pages.css §08)
          .timeline, .timeline-item, .timeline-marker,
          .timeline-body, .timeline-title, .timeline-text
          (pages.css §19 subscription)
          .chart-card, .chart-card-head, .chart-card-title,
          .chart-card-subtitle, .chart-card-body, .chart-card-table
          (app.css §08)
          .dash-metric, .dash-metric-*, .dashboard-chart-card*
          (app.css §02)

     ✅ Filter panel styling matches the surrounding MabunChip
        design system: navy for active states, blue-100 tint for
        counts, radius-pill for chips, small radii for options.

     ✅ Every [data-*] attribute the JS sets is honoured:
          .filter-group[data-collapsed="true"] → hides body
          .filter-chip[aria-pressed="true"]    → active state
          .filter-group-head:focus-visible     → keyboard focus

     ✅ Responsive:
          ≤ 1024px — desktop panel hidden via pages.css
           ≤  640px — pill labels clamp at 160px
           Desktop  — sticky sidebar bounded by viewport height

     ✅ Reduced-motion handled for the two animated elements
        (.filter-chip transitions, .filter-pill-remove).

     ✅ Print rules hide the filter panel and pills entirely.
   ============================================================ */
