/* ══════════════════════════════════════════════════════════════════════════════
   Vendor widget theming.

   select2 and persian-datepicker both ship a light-only stylesheet built for a
   white page. Dropped into this glassmorphism theme untouched, they render as
   bright white rectangles on a near-black page — which is exactly the kind of
   thing that looks fine in a screenshot of one component and awful in the
   product. Every rule below re-points a vendor colour at a design token from
   site.css, so both widgets follow the dark/light toggle for free.

   Load order matters: this file must come AFTER select2.min.css and
   persian-datepicker.css.
════════════════════════════════════════════════════════════════════════════════ */

/* ────────────────────────────── select2 ────────────────────────────────────── */

.select2-container { width: 100% !important; }

/* Closed control — matched to .form-control in site.css so a select2 and a plain
   input sitting next to each other are the same height and colour. */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    min-height: 40px;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

[data-theme="light"] .select2-container--default .select2-selection--single,
[data-theme="light"] .select2-container--default .select2-selection--multiple {
    background: #fff;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(var(--clr-primary-rgb), 0.15);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary);
    line-height: 38px;
    padding-inline-start: 0.85rem;
    padding-inline-end: 2rem;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted);
}

/* The arrow is absolutely positioned with `right` by the vendor, which puts it
   on the wrong side in RTL. */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 38px;
    right: auto;
    left: 6px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--text-secondary) transparent transparent transparent;
}
.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--text-secondary) transparent;
}

/* The "x" that clears a single select. select2 floats it to the inline end with a 20px margin,
   which in RTL is the same left corner the arrow above was moved to: the two landed on top of
   each other, the "x" 12px higher than the caret (seen on the status filter, 1405/08/07).
   Both are pinned absolutely instead, each on its own 38px line: arrow at the edge, clear beside it,
   and the rendered text makes room only when a clear button is actually present. */
.select2-container--default .select2-selection--single .select2-selection__clear {
    float: none;
    position: absolute;
    top: 0;
    left: 24px;
    right: auto;
    height: 38px;
    margin: 0;
    padding: 0 0.3rem;
    display: inline-flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1;
}
.select2-container--default .select2-selection--single.select2-selection--clearable .select2-selection__rendered {
    padding-inline-end: 3.2rem;
}
.select2-container--default .select2-selection--single .select2-selection__clear:hover {
    color: var(--clr-danger);
}

/* Multi-select pills. select2 4.1 renders the remove "x" as a <button> parked with
   position:absolute at the pill's top-left corner, and reserves room for it with a 20px
   padding on the pill. Our pill padding replaced that padding, so the "x" sat outside the
   pill border, in its own little box (seen on the tags field, 1405/08/07). The pill is a
   flex row instead: text first, "x" at the inline end, nothing absolute. */
/* The pills live in a <ul> and the inline search box is the <ul>'s sibling, so with the <ul>
   as a block the search always dropped to a second line (104px for two tags). The control itself
   is the flex row and the <ul> is display:contents: pills and search share one wrapping line.
   select2's RTL rule gives each pill margin-right:auto, which in a flex row pushes the pills to
   opposite ends of the control; it is zeroed below. */
.select2-container--default .select2-selection--multiple {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.5rem;
}
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: contents;
}
.select2-container--default .select2-selection--multiple .select2-search--inline {
    float: none;
    flex: 1 1 5rem;
    min-width: 5rem;
}
.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    width: 100% !important;
    margin: 0;
    height: 1.9rem;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    position: static;
    background: rgba(var(--clr-primary-rgb), 0.16);
    border: 1px solid rgba(var(--clr-primary-rgb), 0.32);
    border-radius: 50px;
    color: var(--text-primary);
    padding: 0.1rem 0.4rem 0.1rem 0.65rem;
    margin: 0;
    line-height: 1.6;
}
.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
    padding: 0.1rem 0.65rem 0.1rem 0.4rem;
    margin: 0;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__display {
    padding: 0;
    order: 1;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    order: 2;
    position: static;
    display: inline-grid;
    place-items: center;
    width: 1.1rem;
    height: 1.1rem;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--clr-primary);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--clr-danger);
}
/* select2's own RTL rule draws a 1px separator on the "x" (border-left) and outranks the
   border:0 above by specificity; it has no job inside a pill. */
.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
    border: 0;
}

/* Open dropdown. z-index sits above .admin-topbar (1020) and below the mobile
   sidebar overlay (1040) so it cannot be trapped under a sticky header. */
.select2-container--default .select2-dropdown {
    background: var(--bg-elevated);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--glass-shadow);
    z-index: 1030;
}

.select2-container--default .select2-results__option {
    color: var(--text-secondary);
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
}
.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted {
    background: rgba(var(--clr-primary-rgb), 0.16);
    color: var(--text-primary);
}
.select2-container--default .select2-results__option[aria-selected="true"],
.select2-container--default .select2-results__option[data-selected="true"] {
    background: rgba(var(--clr-primary-rgb), 0.28);
    color: #fff;
}
/* 28% indigo over a white dropdown is pale lilac; white text on it was unreadable in the light theme
   (the already-chosen tags in the tags dropdown, 1405/08/07). */
[data-theme="light"] .select2-container--default .select2-results__option[aria-selected="true"],
[data-theme="light"] .select2-container--default .select2-results__option[data-selected="true"] {
    color: var(--text-primary);
}
.select2-container--default .select2-results__message {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Search box inside the dropdown. */
.select2-container--default .select2-search--dropdown { padding: 0.5rem; }
.select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.4rem 0.6rem;
    outline: none;
}
.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--clr-primary);
}
.select2-container--default .select2-search--inline .select2-search__field {
    color: var(--text-primary);
}

/* A select2 inside a disabled fieldset must still look disabled. */
.select2-container--disabled .select2-selection--single { opacity: 0.55; }


/* ───────────────────────── persian-datepicker ──────────────────────────────── */

.pdp-popup {
    background: var(--bg-elevated);
    box-shadow: var(--glass-shadow), 0 0 0 1px var(--glass-border);
    border-radius: var(--radius-md);
    /* Above the sticky topbar, same band as the select2 dropdown. */
    z-index: 1030;
}

.pdp-title { color: var(--text-primary); }
.pdp-nav-btn { color: var(--text-secondary); }
.pdp-nav-btn:hover { background: rgba(var(--clr-primary-rgb), 0.12); color: var(--text-primary); }

.pdp-year-input {
    background: var(--bg-surface);
    box-shadow: inset 0 0 0 1px var(--glass-border);
    color: var(--text-primary);
}
.pdp-year-input:focus { box-shadow: inset 0 0 0 2px var(--clr-primary); }

.pdp-weekday { color: var(--text-muted); }
.pdp-day { color: var(--text-secondary); }
.pdp-day:hover { background: rgba(var(--clr-primary-rgb), 0.14); color: var(--clr-primary); }
.pdp-day-today { box-shadow: inset 0 0 0 1px var(--clr-primary); }
.pdp-day-selected,
.pdp-day-selected:hover { background: var(--clr-primary); color: #fff; }
.pdp-day-disabled,
.pdp-day-disabled:hover { color: var(--text-muted); opacity: 0.4; background: transparent; cursor: not-allowed; }

.pdp-footer { border-top: 1px solid var(--glass-border); }
.pdp-link { color: var(--clr-primary); }
.pdp-link-muted { color: var(--text-muted); }

/* Month/year views: header chips and the 3-column cells. */
.pdp-chip { color: var(--text-primary); }
.pdp-chip:hover, .pdp-chip:focus-visible { background: rgba(var(--clr-primary-rgb), 0.12); }
.pdp-hint, .pdp-range { color: var(--text-muted); }
.pdp-cell { color: var(--text-secondary); }
.pdp-cell:hover { background: rgba(var(--clr-primary-rgb), 0.14); color: var(--clr-primary); }
.pdp-cell-current { box-shadow: inset 0 0 0 1px var(--clr-primary); }
.pdp-cell-selected,
.pdp-cell-selected:hover { background: var(--clr-primary); color: #fff; }
.pdp-cell-disabled,
.pdp-cell-disabled:hover { color: var(--text-muted); opacity: 0.4; background: transparent; cursor: not-allowed; }

/* Time picker: the value-as-header chips and the hour/minute grids. */
.ptp-chip-active { background: rgba(var(--clr-primary-rgb), 0.16); color: var(--clr-primary); }
.ptp-colon { color: var(--text-muted); }
.ptp-cell { color: var(--text-secondary); }
.ptp-cell:hover { background: rgba(var(--clr-primary-rgb), 0.14); color: var(--clr-primary); }
.ptp-cell-selected,
.ptp-cell-selected:hover { background: var(--clr-primary); color: #fff; }

/* The visible input is forced LTR by the widget so the digits read naturally.
   These two rules keep it looking like every other .form-control. */
.mcdp-rtl-input {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.5rem 0.85rem;
    width: 100%;
}
[data-theme="light"] .mcdp-rtl-input { background: #fff; }
.mcdp-rtl-input:focus { outline: none; border-color: var(--clr-primary); }

/* Invalid-input feedback from the widget (an out-of-range or half-typed date). */
.mcdp-rtl-input.ring-red-400 { box-shadow: inset 0 0 0 2px var(--clr-danger); }


/* ───────────────────────── time picker (same widget) ───────────────────────── */

/* The popup box itself is already themed above — .ptp-popup reuses .pdp-popup. Only the
   two scrolling columns are its own, and without these the selected hour kept the
   library's stock teal while the selected *day* in the calendar beside it was the
   project's indigo. Same widget, same field, two accent colours. */


.ptp-cell { color: var(--text-secondary); }
.ptp-cell:hover { background: rgba(var(--clr-primary-rgb), 0.14); color: var(--clr-primary); }
.ptp-cell-selected,
.ptp-cell-selected:hover { background: var(--clr-primary); color: #fff; }


/* ───────────────────────── select2 — rich options ──────────────────────────── */

/* templateResult/templateSelection in admin-ui's App.ui.richSelect: avatar + name + role.
   Markup: <span class="s2-rich"><span class="avatar">م</span><span class="s2-rich__t"><b>نام</b><small>نقش</small></span></span> */
.s2-rich { display: flex; align-items: center; gap: 0.6rem; }
.s2-rich .avatar { width: 28px; height: 28px; font-size: 0.75rem; }
.s2-rich__t { display: flex; flex-direction: column; line-height: 1.25; }
.s2-rich__t small { color: var(--text-muted); font-size: 0.72rem; }
.select2-container--default .select2-results__option .s2-rich b { font-weight: 600; }

/* The inline search box of a multi-select sits inside a control that already draws its own focus
   border; site.css's :focus-visible ring would draw a second frame inside it. */
.select2-search--inline .select2-search__field:focus-visible { box-shadow: none !important; }
