/* Searchable multi-select filter — load AFTER site.css / mobile-fix.css */

.mf { position: relative; width: 100%; min-width: 0; }

/* ---------- Trigger ---------- */
.mf-trigger {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    min-height: 38px;
    padding: 0.3rem 0.65rem;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.mf-trigger:hover { background: #fff; border-color: #94a3b8; }
.mf-trigger:focus-visible,
.mf[data-open="true"] .mf-trigger {
    background: #fff;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
    outline: none;
}
.mf[data-has-value="true"] .mf-trigger { background: #eff6ff; border-color: #93c5fd; }

.mf-icon { flex: none; display: inline-flex; width: 16px; height: 16px; color: #64748b; }
.mf[data-has-value="true"] .mf-icon { color: #2563eb; }
.mf-icon svg, .mf-chevron svg, .mf-clear svg { width: 100%; height: 100%; display: block; }

.mf-values { flex: 1; min-width: 0; display: flex; align-items: center; overflow: hidden; }
.mf-placeholder { color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mf-chip {
    display: inline-block;
    max-width: 100%;
    padding: 0.12rem 0.6rem;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mf-badge {
    flex: none;
    min-width: 24px;
    height: 22px;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #2563eb;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.mf-badge[hidden], .mf-clear[hidden], .mf-search-clear[hidden] { display: none; }
.mf-clear {
    flex: none;
    width: 20px;
    height: 20px;
    padding: 3px;
    border-radius: 50%;
    color: #64748b;
    display: inline-flex;
    box-sizing: border-box;
    transition: background 0.15s, color 0.15s;
}
.mf-clear:hover { background: #fee2e2; color: #b91c1c; }
.mf-chevron { flex: none; width: 16px; height: 16px; color: #64748b; transition: transform 0.18s; }
.mf[data-open="true"] .mf-chevron { transform: rotate(180deg); }

/* ---------- Panel (desktop dropdown) ---------- */
.mf-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-start: 0;
    z-index: 1200;
    flex-direction: column;
    min-width: max(100%, 290px);
    max-width: min(380px, calc(100vw - 16px));
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18), 0 2px 6px rgba(15, 23, 42, 0.06);
    overflow: hidden;
    transform-origin: top center;
}
.mf[data-align="left"] .mf-panel { inset-inline-start: auto; left: 0; right: auto; }
.mf[data-align="right"] .mf-panel { inset-inline-start: auto; right: 0; left: auto; }
.mf[data-open="true"] .mf-panel { display: flex; animation: mf-pop 0.16s ease-out; }
@keyframes mf-pop {
    from { opacity: 0; transform: translateY(-6px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.mf-backdrop, .mf-handle, .mf-head, .mf-foot { display: none; }

.mf-search { position: relative; display: flex; align-items: center; margin: 0.65rem 0.65rem 0.4rem; }
.mf-search > svg {
    position: absolute;
    inset-inline-start: 0.7rem;
    width: 16px;
    height: 16px;
    color: #94a3b8;
    pointer-events: none;
}
.mf-input {
    width: 100%;
    height: 40px;
    padding: 0 2.3rem;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 0.88rem;
    outline: none;
    box-sizing: border-box;
}
.mf-input:focus { background: #fff; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.mf-search-clear {
    position: absolute;
    inset-inline-end: 0.45rem;
    width: 24px;
    height: 24px;
    padding: 5px;
    border: none;
    border-radius: 50%;
    background: #e2e8f0;
    color: #475569;
    cursor: pointer;
    display: inline-flex;
    box-sizing: border-box;
}
.mf-search-clear svg { width: 100%; height: 100%; }

.mf-tools {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.1rem 0.75rem 0.5rem;
    border-bottom: 1px solid #eef2f7;
    font-size: 0.76rem;
}
.mf-tools button {
    border: none;
    background: none;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    color: #2563eb;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
}
.mf-tools button:hover:not(:disabled) { background: #eff6ff; }
.mf-tools .mf-none { color: #b91c1c; }
.mf-tools .mf-none:hover:not(:disabled) { background: #fef2f2; }
.mf-tools button:disabled { opacity: 0.4; cursor: not-allowed; }
.mf-summary { margin-inline-start: auto; color: #64748b; font-weight: 600; white-space: nowrap; }

.mf-list {
    list-style: none;
    margin: 0;
    padding: 0.35rem;
    max-height: 280px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.mf-opt {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.6rem;
    border-radius: 9px;
    cursor: pointer;
}
.mf-opt:hover, .mf-opt.is-active { background: #f1f5f9; }
.mf-opt.is-selected { background: #eff6ff; }
.mf-check {
    flex: none;
    width: 20px;
    height: 20px;
    padding: 3px;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: transparent;
    display: inline-flex;
    box-sizing: border-box;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.mf-check svg { width: 100%; height: 100%; }
.mf-opt.is-selected .mf-check { background: #2563eb; border-color: #2563eb; color: #fff; transform: scale(1.06); }
.mf-opt-body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.mf-opt-label {
    font-size: 0.86rem;
    font-weight: 600;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mf-opt-hint {
    font-size: 0.72rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mf-opt mark { background: #fde68a; color: inherit; border-radius: 3px; padding: 0 1px; }
.mf-empty { padding: 1.25rem; text-align: center; color: #64748b; font-size: 0.85rem; }

/* ---------- Mobile: bottom sheet ---------- */
@media (max-width: 767.98px) {
    .mf-trigger { min-height: 42px; }

    .mf-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1500;
        background: rgba(15, 23, 42, 0.5);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s;
    }
    .mf[data-open="true"] .mf-backdrop { opacity: 1; pointer-events: auto; }

    .mf-panel {
        position: fixed;
        inset: auto 0 0 0;
        top: auto;
        z-index: 1510;
        width: 100%;
        min-width: 0;
        max-width: none;
        max-height: 82dvh;
        border: none;
        border-radius: 18px 18px 0 0;
    }
    .mf[data-open="true"] .mf-panel { animation: mf-sheet 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
    @keyframes mf-sheet { from { transform: translateY(100%); } to { transform: none; } }

    .mf-handle { display: block; width: 42px; height: 4px; margin: 0.6rem auto 0.1rem; border-radius: 4px; background: #cbd5e1; }
    .mf-head { display: flex; align-items: center; justify-content: space-between; padding: 0.25rem 1rem 0; }
    .mf-title { font-size: 1rem; font-weight: 800; color: #0f172a; }
    .mf-x {
        width: 34px; height: 34px; padding: 8px;
        border: none; border-radius: 50%;
        background: #f1f5f9; color: #475569;
        display: inline-flex; box-sizing: border-box; cursor: pointer;
    }
    .mf-x svg { width: 100%; height: 100%; }

    .mf-input { height: 44px; font-size: 1rem; } /* 16px stops iOS zoom-on-focus */
    .mf-list { flex: 1; max-height: none; min-height: 140px; }
    .mf-opt { padding: 0.75rem 0.7rem; }
    .mf-opt-label { font-size: 0.95rem; }

    .mf-foot {
        display: block;
        padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #eef2f7;
        background: #fff;
    }
    .mf-done {
        width: 100%; height: 46px;
        border: none; border-radius: 12px;
        background: linear-gradient(135deg, #3b82f6, #2563eb);
        color: #fff; font-size: 1rem; font-weight: 800; cursor: pointer;
    }
}

body.mf-sheet-open { overflow: hidden !important; }

@media (prefers-reduced-motion: reduce) {
    .mf-panel, .mf-backdrop, .mf-check, .mf-chevron { animation: none !important; transition: none !important; }
}

/* ================================================================
   Reports Page: Stable Filters Toolbar & Independent Layout
   Prevents filters from shrinking, collapsing, or clipping
   regardless of table row count (100, 10, 1, or 0 records).
   ================================================================ */

#reportsView {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box;
}

#reportsView .tab-content {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box;
}

/* Dedicated filters toolbar card above the table */
.reports-toolbar-card {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box;
  background: #ffffff !important;
  border: 1px solid #e8eef5 !important;
  border-radius: 14px !important;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04) !important;
  padding: 0.95rem 1.15rem !important;
  margin-bottom: 1rem !important;
  overflow: visible !important; /* Never clip multi-select dropdowns */
  position: relative;
  z-index: 30; /* Keep above table content so dropdowns float cleanly */
}

.reports-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.85rem 1.25rem;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Group containing Search + all Filters */
.reports-filters-group {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  flex: 1 1 0%;
  min-width: 0;
  box-sizing: border-box;
}

/* Individual filter groups (Search or Multi-select) */
.reports-toolbar-card .filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1 1 200px;
  min-width: 180px;
  max-width: 320px;
  box-sizing: border-box;
}

.reports-toolbar-card .filter-group label {
  font-size: 0.74rem !important;
  font-weight: 700 !important;
  color: #64748b !important;
  text-align: right;
  margin: 0;
  user-select: none;
  line-height: 1.2;
}

/* Search input wrapper with icon matching Global Filters pattern */
.reports-search-group {
  flex: 1 1 240px !important;
  min-width: 200px !important;
  max-width: 340px !important;
}

.reports-search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.reports-search-icon {
  position: absolute;
  inset-inline-start: 0.65rem;
  width: 16px;
  height: 16px;
  color: #94a3b8;
  pointer-events: none;
  z-index: 2;
}

.reports-search-input {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  min-height: 38px !important;
  height: 38px !important;
  padding: 0.3rem 0.65rem !important;
  padding-inline-start: 2rem !important;
  border-radius: 9px !important;
  border: 1px solid #cbd5e1 !important;
  background: #f8fafc !important;
  color: #0f172a !important;
  font-size: 0.85rem !important;
  box-sizing: border-box;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.reports-search-input:hover {
  background: #fff !important;
  border-color: #94a3b8 !important;
}

.reports-search-input:focus {
  background: #fff !important;
  border-color: #2563eb !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14) !important;
  outline: none !important;
}

/* Actions group: Export Excel & Print buttons */
.reports-actions-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-inline-start: auto;
  align-self: flex-end;
  box-sizing: border-box;
}

.reports-actions-group .btn {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 9px;
  white-space: nowrap;
}

/* Independent table container below toolbar */
.reports-table-container {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box;
  background: #ffffff !important;
  border: 1px solid #e8eef5 !important;
  border-radius: 16px !important;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04) !important;
  padding: 1rem 1.1rem 1.15rem !important;
  margin-bottom: 1rem;
  overflow: hidden;
  position: relative;
  z-index: 10;
}

.reports-table-container .data-table-wrapper {
  width: 100% !important;
  min-width: 0 !important;
  overflow-x: auto !important;
  box-sizing: border-box;
}

.reports-table-container table.data-table {
  width: 100% !important;
  min-width: 900px;
}

/* Print handling: Hide toolbar when printing report */
@media print {
  .reports-toolbar-card {
    display: none !important;
  }
}
body.printing-report .reports-toolbar-card {
  display: none !important;
}

/* Tablet & Mobile responsiveness */
@media (max-width: 768px) {
  .reports-toolbar-card {
    padding: 0.75rem 0.85rem !important;
  }
  .reports-toolbar-card .filter-group,
  .reports-search-group {
    flex: 1 1 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
  .reports-actions-group {
    width: 100%;
    justify-content: stretch;
  }
  .reports-actions-group .btn {
    flex: 1;
  }
}