/*
 * «فیلدهای جست‌وجو» و «جابه‌جایی ستون‌ها» — تسک ۱۴۰۵/۰۷/۲۸/۰۱
 *
 * The heading checkboxes are only shown while the table's search is in use
 * (`.agency-search-fields-active`, set by agency-table-search-fields.js);
 * the «انتخاب فیلدهای جست‌وجو» control joined to the box is always there,
 * which is what a phone uses.
 */

.agency-search-heading-field {
    display: none;
    align-items: center;
    margin-inline-end: 0.375rem;
    vertical-align: middle;
    cursor: pointer;
}

.agency-search-fields-active .agency-search-heading-field {
    display: inline-flex;
}

.agency-search-heading-field input,
.agency-search-fields-option input {
    width: 1rem;
    height: 1rem;
    accent-color: var(--warning-500, #f59e0b);
    cursor: pointer;
}

.fi-ta-header-cell:has(.agency-search-heading-field) {
    white-space: nowrap;
}

.fi-ta-header-cell > .agency-search-heading-field + * {
    display: inline-flex;
}

/*
 * ─── The toolbar of every table — تسک ۰۲ (بازطراحی هدر مدیریت‌ها، بند ۷ … ۱۲) ───
 *
 * Read left to right, as the owner's reference picture A reads it:
 *
 *   «جابه‌جایی ستون‌ها»   [☑ ۴ | 🔍 جست‌وجو]   ⏷
 *
 * the column arranger first, at the very left edge of the toolbar; then the
 * field picker joined to the search box; then the table's filter, on the far
 * side of the box. Filament writes them in another order (box, what is hung
 * after it, filter, arranger), so the order is set here, on the shared row,
 * for every table at once — and anything a page hangs after the box (a kind
 * select, a sort toggle) stands to the right of the filter, never between the
 * filter and the box or between the box and its picker.
 *
 * The three groups stand a short, fixed step apart, the panel's own 0.5rem;
 * the picker and the box stand 0px apart, in one `.agency-search-group`
 * (the panel's copy of Filament's search field), so no wrap can part them.
 */
.fi-ta-ctn .fi-ta-header-toolbar {
    --agency-toolbar-gap: calc(var(--spacing, 0.25rem) * 2);
    --agency-toolbar-control-height: 2.25rem;

    /* بند ۱۱: nothing before the arranger — its left edge is the left edge
       of the table's own box, which on a management's page is the left edge
       of the buttons in the page's heading row above it. */
    padding-inline-end: 0;
}

.fi-ta-ctn .fi-ta-header-toolbar > div:has(> .agency-search-group, > .fi-ta-col-manager-dropdown, > .fi-ta-filters-dropdown, > .fi-ta-filters-modal, > .fi-ta-filters-trigger-action-ctn) {
    flex-wrap: wrap;
    justify-content: flex-end;
    column-gap: var(--agency-toolbar-gap);
    row-gap: var(--agency-toolbar-gap);
    min-width: 0;
    max-width: 100%;
    /* تسک ۰۳، بند ۱۱: the group takes the rest of its row, so that when the
       toolbar wraps — a sort or a bulk action on a row of its own, a tablet's
       width — the arranger is still packed against the left edge rather than
       left wherever the group's own width ended. */
    flex: 1 1 auto;
}

.fi-ta-header-toolbar .fi-ta-filters-dropdown,
.fi-ta-header-toolbar .fi-ta-filters-modal,
.fi-ta-header-toolbar .fi-ta-filters-trigger-action-ctn {
    order: 1;
}

.fi-ta-header-toolbar .agency-search-group {
    order: 2;
}

.fi-ta-header-toolbar .fi-ta-col-manager-dropdown {
    order: 3;
}

/* بند ۱۲.۱: one height for the row — the box's own 2.25rem. The filter keeps
   its plain icon, but the area that answers a click is as tall as the rest. */
.fi-ta-header-toolbar [data-agency-column-manager-trigger] {
    min-height: var(--agency-toolbar-control-height);
}

.fi-ta-header-toolbar .fi-ta-filters-dropdown > .fi-dropdown-trigger > .fi-icon-btn,
.fi-ta-header-toolbar .fi-ta-filters-modal > .fi-modal-trigger > .fi-icon-btn,
.fi-ta-header-toolbar .fi-ta-filters-trigger-action-ctn > .fi-icon-btn {
    width: var(--agency-toolbar-control-height);
    height: var(--agency-toolbar-control-height);
    /* Filament pulls an icon button out by half a rem on each side so its
       glyph lines up with text; here the button's own box is the area, so the
       0.5rem step to the search box is a real one. */
    margin: 0;
}

/* ─── The box and its picker: two controls, drawn as one (بند ۹) ─── */

.agency-search-group {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    max-width: 100%;
    min-width: 0;
}

.agency-search-group > .fi-ta-search-field {
    min-width: 0;
}

/* The box keeps its rounded outer side; the side that meets the picker — the
   left, in this right-to-left panel — is square, and its own ring is the one
   fine line between the two. */
.agency-search-group-with-fields > .fi-ta-search-field .fi-input-wrp {
    position: relative;
    z-index: 1;
    border-start-end-radius: 0;
    border-end-end-radius: 0;
}

.agency-search-fields {
    position: relative;
    display: inline-flex;
}

.agency-search-fields-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    box-sizing: border-box;
    height: 100%;
    min-height: 2.25rem;
    min-width: 2.75rem;
    padding: 0 0.5rem;
    border-start-start-radius: 0;
    border-end-start-radius: 0;
    border-start-end-radius: 0.5rem;
    border-end-end-radius: 0.5rem;
    color: var(--gray-700, #374151);
    background: #ffffff;
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--gray-950, #030712) 10%, transparent);
    /* The ring on the side that meets the box is cut away, so the joint is the
       box's one line — never two lines side by side. */
    clip-path: inset(-4px 0 -4px -4px);
    white-space: nowrap;
    cursor: pointer;
}

[dir="ltr"] .agency-search-fields-trigger {
    clip-path: inset(-4px -4px -4px 0);
}

.dark .agency-search-fields-trigger {
    color: var(--gray-200, #e5e7eb);
    background: color-mix(in oklab, #ffffff 5%, transparent);
    box-shadow: 0 0 0 1px color-mix(in oklab, #ffffff 20%, transparent);
}

.agency-search-fields-trigger:hover {
    background: color-mix(in oklab, var(--warning-400, #fbbf24) 12%, #ffffff);
}

.dark .agency-search-fields-trigger:hover {
    background: color-mix(in oklab, var(--warning-400, #fbbf24) 12%, transparent);
}

/* Focus shows on the control that has it, on all four sides. */
.agency-search-fields-trigger:focus-visible {
    z-index: 2;
    clip-path: none;
    outline: 2px solid var(--warning-500, #f59e0b);
    outline-offset: 0;
}

.agency-search-fields-trigger-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.agency-search-fields-count {
    min-width: 1.125rem;
    height: 1.125rem;
    padding: 0 0.25rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1.125rem;
    text-align: center;
    color: #000000;
    background: var(--warning-400, #fbbf24);
}

.agency-search-fields-tooltip {
    position: absolute;
    top: calc(100% + 0.375rem);
    inset-inline-end: 0;
    z-index: 50;
    display: none;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.25rem;
    white-space: nowrap;
    color: #ffffff;
    background: #18181b;
    pointer-events: none;
}

/* A sibling of the button, not inside it: the button's clip would cut it. */
.agency-search-fields-trigger:hover + .agency-search-fields-tooltip,
.agency-search-fields-trigger:focus-visible + .agency-search-fields-tooltip {
    display: block;
}

/* While the list is open its tooltip stays hidden. Read off the button's own
   `aria-expanded`, a sibling of the tooltip — never a `:has()` that inspects
   the list's inline `style`: Chrome cannot narrow a `:has()` on an attribute
   substring, so every inline-style change anywhere on the page (a menu
   opening, Alpine's `x-show`, a dropdown being placed) re-styled the whole
   page. That rule was the root of the panel's freezes (تسک ۰۳). */
.agency-search-fields-trigger[aria-expanded="true"] + .agency-search-fields-tooltip {
    display: none;
}

.agency-search-fields-panel {
    position: absolute;
    inset-inline-end: 0;
    top: calc(100% + 0.375rem);
    z-index: 40;
    width: max-content;
    min-width: 14rem;
    max-width: min(20rem, calc(100vw - 2rem));
    max-height: 60vh;
    overflow-y: auto;
    padding: 0.75rem;
    border-radius: 0.75rem;
    background: #ffffff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, .15), 0 0 0 1px color-mix(in oklab, var(--gray-950, #030712) 8%, transparent);
}

.dark .agency-search-fields-panel {
    background: var(--gray-900, #111827);
}

.agency-search-fields-panel-title {
    margin-bottom: 0.5rem;
    font-weight: 700;
    color: var(--warning-600, #d97706);
}

.agency-search-fields-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.25rem;
    border-radius: 0.375rem;
    cursor: pointer;
}

.agency-search-fields-option:hover {
    background: color-mix(in oklab, var(--warning-400, #fbbf24) 15%, transparent);
}

.agency-search-fields-panel-hint {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--gray-500, #6b7280);
}

/* «جابه‌جایی ستون‌ها»: the icon and the words, side by side, on one line. */
[data-agency-column-manager-trigger] {
    white-space: nowrap;
}

/* A phone: the list opens across the screen rather than off its edge. */
@media (max-width: 640px) {
    .agency-search-fields-panel {
        position: fixed;
        top: 7rem;
        left: 1rem;
        right: 1rem;
        width: auto;
        max-width: none;
    }
}
