/* public/assets/css/filter-drawer.css
 *
 * Mobile-only floating "Filters" drawer. Paired with filter-drawer.js, which
 * auto-detects GET filter forms app-wide and relocates their select/date/
 * number/checkbox/radio fields into the panel this file styles — no
 * per-view markup changes required (same "one global lever" philosophy as
 * responsive-tables.js / ui-globals.css's mobile breakpoint sections).
 *
 * What lives here:
 *   .fd-fab            floating "Filters" pill, fixed bottom-right
 *   .fd-backdrop        semi-transparent overlay behind the drawer
 *   .fd-drawer          the panel itself, slides in from the right
 *   .fd-field / -inline wrappers the JS builds around each relocated field
 *   .fd-btn-apply/-reset drawer footer actions
 *
 * Theme: reuses the app's real tokens (--primary-color #162B30,
 * --secondary-color #164346, both defined in every layout's <style> block)
 * and the .stat-card shadow/radius convention (10px radius,
 * 0 1px 3px rgba(0,0,0,.1)) scaled up slightly for a floating/overlay
 * surface. No unrelated hardcoded hex colors are introduced; the greys used
 * for borders/hover states (#e7ecea, #f4f6f8, #d1d5db, #5b6b66, #1a2b27)
 * are the same neutrals already used by .app-tabs / .btn-back in
 * ui-globals.css, kept for visual consistency with the rest of the chrome
 * this app already ships.
 *
 * Scope: everything here is gated to <=1024px (tablet and below — the drawer
 * activates "starting from tablets" per an explicit ask, not just phones).
 * At >=1025px (desktop) the fab/backdrop/drawer are force-hidden regardless
 * of JS state, so the existing inline filter bar is guaranteed untouched on
 * desktop even if a script bug ever left the drawer DOM in place after a
 * resize.
 */

/* ── Floating "Filters" button ───────────────────────────────────────────── */
.fd-fab {
  position: fixed;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 9px 13px;
  border: none;
  border-radius: 999px;
  background: var(--primary-color);
  color: #ffffff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: padding 0.25s ease, box-shadow 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}
.fd-fab:hover {
  background: var(--secondary-color);
}
.fd-fab i {
  font-size: 10px;
}

/* The label text collapses away (rather than the button just going display:none)
   so the shrink reads as a smooth "retract", not a flicker. */
.fd-fab-label {
  max-width: 100px;
  overflow: hidden;
  white-space: nowrap;
  opacity: 1;
  transition: max-width 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
}

/* Applied by filter-drawer.js while the page is actively scrolling (see the
   scroll+debounce handler) — shrinks to an icon-only circle so the button
   blocks less content while the user is mid-scroll, then the label re-grows
   ~280ms after scrolling stops. */
.fd-fab--retract {
  padding: 9px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.fd-fab--retract .fd-fab-label {
  max-width: 0;
  opacity: 0;
  margin: 0;
}

/* Applied while the drawer is open — the fab sits behind the backdrop/drawer
   anyway, so tuck it away entirely instead of leaving a dead click target. */
.fd-fab--open-hidden {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

/* ── Backdrop ─────────────────────────────────────────────────────────────── */
.fd-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5); /* same tone as .sidebar-overlay in dashboard.php */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 65;
}
.fd-backdrop--open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Drawer panel ─────────────────────────────────────────────────────────── */
/* Deliberately nested inside the source <form> by filter-drawer.js (not
   appended to <body>) so the relocated fields stay real form controls —
   position:fixed still docks to the viewport as long as no ancestor sets
   transform/filter/perspective, which none of this app's layout wrappers do. */
.fd-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  height: 100dvh;
  width: min(86vw, 340px);
  background: #ffffff;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.18);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 70;
  display: flex;
  flex-direction: column;
  will-change: transform;
}
.fd-drawer--open {
  transform: translateX(0);
}

.fd-drawer-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #e7ecea;
}
.fd-drawer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--primary-color);
}
.fd-drawer-close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: #f4f6f8;
  color: #5b6b66;
  font-size: 15px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.fd-drawer-close:hover {
  background: #e7ecea;
  color: #1a2b27;
}

.fd-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* One wrapper per relocated field (built by filter-drawer.js). Stacks the
   field's own <label>, if it had one, above the control — full width, thumb
   friendly, independent of whatever flex/grid classes the original inline
   layout used (those still apply to the control itself but are harmless
   here since a single flex child ignores its own flex-basis in this
   context). */
.fd-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fd-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary-color);
}
/* Neutralize layout utility classes (e.g. Tailwind's flex-1 / basis-[...])
   that came along for the ride on the moved control — in the drawer's
   column layout those would otherwise stretch or misalign the field. */
.fd-field > select,
.fd-field > input {
  width: 100% !important;
  flex: 0 0 auto !important;
}
.fd-field select,
.fd-field input[type="date"],
.fd-field input[type="number"] {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  background: #ffffff;
  color: #1a2b27;
}
.fd-field select:focus,
.fd-field input:focus {
  outline: 2px solid var(--secondary-color); /* matches .focus:ring-secondary in dashboard.php */
  outline-offset: 1px;
  border-color: var(--secondary-color);
}

/* Checkbox/radio fields read better as a single row (control beside its
   label) than stacked — filter-drawer.js adds this modifier class instead
   of relying on :has() for older-browser safety. */
.fd-field--inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.fd-field--inline > select,
.fd-field--inline > input {
  width: auto !important;
}
.fd-field--inline input[type="checkbox"],
.fd-field--inline input[type="radio"] {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}
.fd-field--inline label {
  order: 2;
  font-size: 14px;
  font-weight: 500;
  color: #1a2b27;
}
.fd-field--inline input {
  order: 1;
}

.fd-drawer-footer {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #e7ecea;
}
.fd-btn {
  flex: 1;
  min-height: 44px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
}
.fd-btn-apply {
  background: var(--primary-color);
  color: #ffffff;
}
.fd-btn-apply:hover {
  background: var(--secondary-color);
}
.fd-btn-reset {
  background: #ffffff;
  border-color: #d1d5db;
  color: var(--secondary-color);
}
.fd-btn-reset:hover {
  background: #f4f6f8;
}

/* Prevent the page scrolling behind an open drawer. */
body.fd-body-locked {
  overflow: hidden;
}

/* ── Desktop: guarantee zero visual impact ───────────────────────────────────
 * filter-drawer.js only activates (moves fields, shows the fab) at tablet
 * width and below (<=1024px) and restores everything above it, but this
 * rule is a hard backstop: even if the drawer DOM is ever left in the tree
 * at desktop width, none of it can render or be interacted with, so the
 * existing inline filter bar (untouched by this feature) is always what
 * desktop users see. */
@media (min-width: 1025px) {
  .fd-fab,
  .fd-backdrop,
  .fd-drawer {
    display: none !important;
  }
}
