/* ============================================================
   .tnt-filter-drawer — canonical tenant filter drawer primitive
   ------------------------------------------------------------
   Source of truth: the remedials tracker board filter drawer.
   Bottom-sheet on mobile with sticky footer + safe-area padding.
   Desktop: unwraps via `display: contents` so filters render inline.

   BEM:
     .tnt-filter-drawer               root
       .tnt-filter-drawer__overlay    scrim (also accepts .modal__overlay)
       .tnt-filter-drawer__panel      the bottom-sheet dialog
         .tnt-filter-drawer__head     sticky header
           .tnt-filter-drawer__eyebrow
           .tnt-filter-drawer__title
           .tnt-filter-drawer__close  (or .modal__close)
         .tnt-filter-drawer__body     scrollable body
         .tnt-filter-drawer__foot     sticky footer
           .tnt-filter-drawer__foot-actions   button grid
   ============================================================ */

/* ---------- Desktop (default) ----------
   Drawer markup becomes inline filters.
   style.css has :where([hidden]){display:none!important}; counter
   with !important so [hidden] is meaningful only on mobile. */
.tnt-filter-drawer,
.tnt-filter-drawer[hidden] {
  display: contents !important;
}

.tnt-filter-drawer > .tnt-filter-drawer__overlay,
.tnt-filter-drawer > .modal__overlay,
.tnt-filter-drawer__head,
.tnt-filter-drawer__foot,
.tnt-filter-drawer__close,
.tnt-filter-drawer__head > .modal__close {
  display: none;
}

.tnt-filter-drawer__panel,
.tnt-filter-drawer__body {
  display: contents;
}

/* ---------- Mobile (≤900px): bottom-sheet drawer ---------- */
@media (max-width: 900px) {
  .tnt-filter-drawer,
  .tnt-filter-drawer[hidden] {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 1400;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .18s ease, visibility .18s ease;
  }

  .tnt-filter-drawer.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .tnt-filter-drawer > .tnt-filter-drawer__overlay,
  .tnt-filter-drawer > .modal__overlay {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 0;
    border: 0;
    background: rgba(26, 24, 21, 0.42);
    cursor: pointer;
  }

  .tnt-filter-drawer__panel {
    display: flex;
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    z-index: 1;
    max-height: min(86vh, 760px);
    flex-direction: column;
    background: var(--canvas, #f7f5f0);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.18);
    overflow: hidden;
  }

  .tnt-filter-drawer__head,
  .tnt-filter-drawer__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 18px;
    background: var(--surface-card, #ffffff);
    flex-shrink: 0;
  }

  .tnt-filter-drawer__head {
    border-bottom: 1px solid var(--rule, rgba(26, 24, 21, 0.08));
    position: sticky;
    top: 0;
    z-index: 3;
  }

  .tnt-filter-drawer__eyebrow {
    margin: 0 0 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-strong, #a97807);
  }

  .tnt-filter-drawer__title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink, #1a1815);
    line-height: 1.3;
  }

  .tnt-filter-drawer__close,
  .tnt-filter-drawer__head > .modal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--rule-strong, rgba(26, 24, 21, 0.14));
    border-radius: 12px;
    background: var(--surface-card, #ffffff);
    color: var(--ink-3, #6b6458);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
  }

  .tnt-filter-drawer__body {
    display: block;
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
  }

  .tnt-filter-drawer__foot {
    border-top: 1px solid var(--rule, rgba(26, 24, 21, 0.08));
    position: sticky;
    bottom: 0;
    z-index: 3;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }

  .tnt-filter-drawer__foot-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 10px;
    width: 100%;
  }

  /* Canonical odd-last-child rule: 1 button full-width,
     2 row-of-2, 3 as 1-full + 2-row (this handles the 3rd child
     odd case); 4 fills a 2x2 grid. */
  .tnt-filter-drawer__foot-actions > *:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  /* Prevent body scroll while drawer is open. JS toggles this. */
  body.tnt-filter-drawer-open {
    overflow: hidden;
  }

  /* --------------------------------------------------------
     Inline action wrappers inside drawer body
     --------------------------------------------------------
     9 legacy templates put their Apply/Clear/Export buttons
     inline at the end of the form body (not in a proper
     .tnt-filter-drawer__foot). This catches those wrappers
     and applies the canonical 2-col grid + odd-last-child
     rule so buttons lay out as a row of 2 (or 1-full + 2-row
     for 3 buttons).
     -------------------------------------------------------- */
  .tnt-filter-drawer__body .team-filter-actions,
  .tnt-filter-drawer__body .security-alerts-filter-actions,
  .tnt-filter-drawer__body .analytics-tab-filter-actions,
  .tnt-filter-drawer__body .analytics-scope-actions,
  .tnt-filter-drawer__body .inv-filter-actions,
  .tnt-filter-drawer__body .qpi-filter-actions,
  .tnt-filter-drawer__body .rpi-filter-actions,
  .tnt-filter-drawer__body .clients-filter-actions,
  .tnt-filter-drawer__body .jobs-client-directory-filter-actions,
  .tnt-filter-drawer__body .property-workspace-filter-bar__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-top: 12px;
  }

  .tnt-filter-drawer__body .team-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .security-alerts-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .analytics-tab-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .analytics-scope-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .inv-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .qpi-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .rpi-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .clients-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .jobs-client-directory-filter-actions > *:last-child:nth-child(odd),
  .tnt-filter-drawer__body .property-workspace-filter-bar__actions > *:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  /* Every button inside an inline action wrapper stretches to
     fill its grid cell and meets the 44px touch target. */
  .tnt-filter-drawer__body .team-filter-actions > *,
  .tnt-filter-drawer__body .security-alerts-filter-actions > *,
  .tnt-filter-drawer__body .analytics-tab-filter-actions > *,
  .tnt-filter-drawer__body .analytics-scope-actions > *,
  .tnt-filter-drawer__body .inv-filter-actions > *,
  .tnt-filter-drawer__body .qpi-filter-actions > *,
  .tnt-filter-drawer__body .rpi-filter-actions > *,
  .tnt-filter-drawer__body .clients-filter-actions > *,
  .tnt-filter-drawer__body .jobs-client-directory-filter-actions > *,
  .tnt-filter-drawer__body .property-workspace-filter-bar__actions > * {
    width: 100%;
    min-height: 44px;
    justify-content: center;
    display: inline-flex;
    align-items: center;
  }
}

/* ---------- Dark mode ---------- */
html[data-theme="dark"] .tnt-filter-drawer__panel {
  background: rgba(15, 23, 42, 0.95);
}

html[data-theme="dark"] .tnt-filter-drawer__head,
html[data-theme="dark"] .tnt-filter-drawer__foot {
  background: rgba(2, 6, 23, 0.6);
  border-color: rgba(71, 85, 105, 0.58);
}

html[data-theme="dark"] .tnt-filter-drawer__title {
  color: #f1f5f9;
}

html[data-theme="dark"] .tnt-filter-drawer__eyebrow {
  color: #e3b008;
}

html[data-theme="dark"] .tnt-filter-drawer__close,
html[data-theme="dark"] .tnt-filter-drawer__head > .modal__close {
  background: rgba(15, 23, 42, 0.7);
  border-color: rgba(148, 163, 184, 0.22);
  color: #cbd5e1;
}

html[data-theme="dark"] .tnt-filter-drawer > .tnt-filter-drawer__overlay,
html[data-theme="dark"] .tnt-filter-drawer > .modal__overlay {
  background: rgba(2, 6, 23, 0.6);
}
