/* Select2 custom styles for tickets page */

:root {
    /* Hierarchy (Select2 templateResult) */
    --tickets-select2-hier-root: #1f2937;
    --tickets-select2-hier-root-dark: rgb(243 244 246);
    --tickets-select2-hier-mid: #374151;
    --tickets-select2-hier-mid-dark: rgb(209 213 219);
    --tickets-select2-hier-sub: #6b7280;
    --tickets-select2-hier-sub-dark: rgb(156 163 175);

    /* Light single selection (tickets filters, html:not(.dark)) */
    --tickets-select2-selection-border: #d1d5db;
    --tickets-select2-selection-surface: white;
    --tickets-select2-selection-text: rgb(55, 65, 81);
    --tickets-select2-selection-placeholder: #9ca3af;
    --tickets-select2-selection-muted: rgb(156, 163, 175);
    --tickets-select2-selection-clear-hover: #6b7280;
    --tickets-select2-selection-arrow: #9ca3af;

    /* Kanban sidebar (dark panel) */
    --tickets-select2-kanban-surface: rgb(55, 65, 81);
    --tickets-select2-kanban-border: rgb(75, 85, 99);
    --tickets-select2-kanban-text: rgb(229, 231, 235);
    --tickets-select2-kanban-highlight-bg: rgb(75, 85, 99);
    --tickets-select2-kanban-highlight-text: rgb(255, 255, 255);

    /* Checkboxes, row indicator, search focus */
    --tickets-select2-checkbox-border: rgb(209, 213, 219);
    --tickets-select2-checkbox-surface: white;
    --tickets-select2-checkbox-border-hover: rgb(156, 163, 175);
    --tickets-select2-accent: rgb(22, 163, 74);
    --tickets-select2-accent-ring: rgba(22, 163, 74, 0.5);
    --tickets-select2-checkmark: white;

    /* Table checkbox (dark) */
    --tickets-select2-checkbox-border-dark: rgb(75, 85, 99);
    --tickets-select2-checkbox-surface-dark: rgb(55, 65, 81);
    --tickets-select2-checkbox-border-hover-dark: rgb(107, 114, 128);
}

/* Main wrapper for each filter Select2 on tickets list (Tailwind mt-4: 1rem) */
.select2-margin {
    margin-top: 0.25rem;
}

/* These selects have options in HTML and are initialized immediately */
#priority_select2:not(.select2-hidden-accessible),
#ticket-org-rules-list-sort-field:not(.select2-hidden-accessible),
#category_select2:not(.select2-hidden-accessible) {
    opacity: 0 !important;
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    pointer-events: none !important;
}

#search{
    padding-left: 35px!important;
}

/*
 * Hierarchical Select2 templateResult (notes category, tickets category/project):
 * use these classes instead of inline hex so options stay readable in dark mode.
 */
html:not(.dark) .select2-results__option .select2-hier-root {
    color: var(--tickets-select2-hier-root) !important;
}
html.dark .select2-results__option .select2-hier-root {
    color: var(--tickets-select2-hier-root-dark) !important;
}

html:not(.dark) .select2-results__option .select2-hier-mid {
    color: var(--tickets-select2-hier-mid) !important;
}
html.dark .select2-results__option .select2-hier-mid {
    color: var(--tickets-select2-hier-mid-dark) !important;
}

html:not(.dark) .select2-results__option .select2-hier-sub {
    color: var(--tickets-select2-hier-sub) !important;
}
html.dark .select2-results__option .select2-hier-sub {
    color: var(--tickets-select2-hier-sub-dark) !important;
}
/*
 * Light-mode-only Select2 single styling (layout: height, flex, arrow position).
 * Scoped with html:not(.dark) so dark mode is driven solely by theme.css (html.dark …)
 * and we avoid fighting global !important / white backgrounds on tickets and elsewhere.
 */
html:not(.dark) .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single {
    border: 1px solid var(--tickets-select2-selection-border);
    border-radius: 0.5rem;
    height: 42px;
    padding: 0;
    display: flex;
    align-items: center;
    background-color: var(--tickets-select2-selection-surface);
    position: relative;
}

html:not(.dark) .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__rendered {
    /* Do not use line-height equal to outer height: border-box clips inner area and bg covers top/bottom borders */
    line-height: 1.25rem;
    color: var(--tickets-select2-selection-text) !important;
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    min-height: 0;
}

html:not(.dark) .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__placeholder {
    color: var(--tickets-select2-selection-placeholder);
    font-weight: 400;
    padding-left: 15px!important;
}

/* Clear button (icône x) - positionné à droite du texte, avant la flèche */
html:not(.dark) .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__clear {
    color: var(--tickets-select2-selection-muted) !important;
    font-size: 1.25rem !important;
    line-height: 1 !important;
    padding-bottom: 0.5rem;
    margin-right: 0 !important;
}

html:not(.dark) .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__clear:hover {
    color: var(--tickets-select2-selection-clear-hover);
}

html:not(.dark) .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__arrow {
    height: 38px;
    right: 0.75rem;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    position: absolute;
}

html:not(.dark) .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__arrow b {
    border-color: var(--tickets-select2-selection-arrow) transparent transparent transparent;
    border-style: solid;
    border-width: 5px 4px 0 4px;
    height: 0;
    width: 0;
    margin-left: -4px;
    margin-top: -2px;
}

/* In dark mode, keep layout-only rules (no colors) so theme.css tokens apply */
html.dark .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single {
    border-radius: 0.5rem;
    height: 42px;
    padding: 0;
    display: flex;
    align-items: center;
    position: relative;
}

html.dark .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__rendered {
    line-height: 1.25rem;
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    min-height: 0;
}

html.dark .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__placeholder {
    font-weight: 400;
    padding-left: 15px!important;
}

html.dark .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__clear {
    font-size: 1.25rem !important;
    line-height: 1 !important;
    padding-bottom: 0.5rem;
    margin-right: 0 !important;
}

html.dark .select2-container--default:not(.organization-select2):not(#select2-headerOrganizationSelector-container) .select2-selection--single .select2-selection__arrow {
    height: 38px;
    right: 0.75rem;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    position: absolute;
}

/* Note: Hover and focus styles are managed globally in global-fields.css */
/* Dropdown, search field, and results styles are now managed globally in global-fields.css */

/* Note: Z-index is now managed globally in global-fields.css (z-index: 30) */
/* Specific positioning for "Assigné à" select below */

/* Spécifique pour le select "Assigné à" */
#select2-assigned_to_select2-container {
    position: relative;
    z-index: 1;
}

#select2-assigned_to_select2-container.select2-container--open {
    z-index: 30 !important;
}

/* S'assurer que le dropdown est correctement positionné */
#select2-assigned_to_select2-container .select2-dropdown {
    position: absolute !important;
    z-index: 30 !important;
    margin-top: 4px !important;
}

/* Note: General dropdown positioning is managed globally in global-fields.css */
/* Specific positioning rules for "Assigné à" select are kept below */

/* Kanban Sidebar Select2 Styles */
#kanban_category_select,
#kanban_project_select,
#kanban_assigned_select,
#kanban_beneficiaire_select {
    font-size: 0.875rem;
}

/* Kanban Sidebar Select2 Container */
.w-80 .select2-container--default .select2-selection--single {
    height: 38px;
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.w-80 .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 38px;
    font-size: 0.875rem;
}

.w-80 .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 38px;
}

/* Kanban Sidebar Select2 Dropdown */
.w-80 .select2-dropdown {
    font-size: 0.875rem;
}

/* Dark Mode Support for Kanban Sidebar */
.dark .w-80 .select2-container--default .select2-selection--single {
    background-color: var(--tickets-select2-kanban-surface);
    border-color: var(--tickets-select2-kanban-border);
    color: var(--tickets-select2-kanban-text);
}

.dark .w-80 .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--tickets-select2-kanban-text);
}

.dark .w-80 .select2-dropdown {
    background-color: var(--tickets-select2-kanban-surface);
    border-color: var(--tickets-select2-kanban-border);
}

.dark .w-80 .select2-results__option {
    color: var(--tickets-select2-kanban-text);
}

.dark .w-80 .select2-results__option--highlighted {
    background-color: var(--tickets-select2-kanban-highlight-bg) !important;
    color: var(--tickets-select2-kanban-highlight-text) !important;
}


/* Filament-style checkbox styling for table checkboxes only */
table input[type="checkbox"]:not(.filter-checkbox) {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--tickets-select2-checkbox-border);
    border-radius: 0.25rem;
    background-color: var(--tickets-select2-checkbox-surface);
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease-in-out;
}

table input[type="checkbox"]:not(.filter-checkbox):hover {
    border-color: var(--tickets-select2-checkbox-border-hover);
}

table input[type="checkbox"]:not(.filter-checkbox):focus {
    outline: none !important;
    box-shadow: 0 0 0 2px var(--tickets-select2-accent-ring) !important;
    border-color: var(--tickets-select2-accent) !important;
}

table input[type="checkbox"]:not(.filter-checkbox):checked {
    background-color: var(--tickets-select2-accent) !important;
    border-color: var(--tickets-select2-accent) !important;
}

table input[type="checkbox"]:not(.filter-checkbox):checked::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0.375rem;
    height: 0.625rem;
    border: solid var(--tickets-select2-checkmark);
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -60%) rotate(45deg);
}

/* Green vertical line for selected rows (Alpine localSelected only – no :has to avoid bar staying after uncheck) */
tr.row-selected td:first-child {
    position: relative;
}

tr.row-selected td:first-child::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--tickets-select2-accent);
}

/* Dark mode support */
.dark table input[type="checkbox"]:not(.filter-checkbox) {
    border-color: var(--tickets-select2-checkbox-border-dark);
    background-color: var(--tickets-select2-checkbox-surface-dark);
}

.dark table input[type="checkbox"]:not(.filter-checkbox):hover {
    border-color: var(--tickets-select2-checkbox-border-hover-dark);
}

.dark table input[type="checkbox"]:not(.filter-checkbox):checked {
    background-color: var(--tickets-select2-accent) !important;
    border-color: var(--tickets-select2-accent) !important;
}

.dark table input[type="checkbox"]:not(.filter-checkbox):focus {
    box-shadow: 0 0 0 2px var(--tickets-select2-accent-ring) !important;
    border-color: var(--tickets-select2-accent) !important;
}

.dark tr.row-selected td:first-child {
    position: relative;
}

.dark tr.row-selected td:first-child::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--tickets-select2-accent);
}

/* Force Filament color for search input focus */
/* Note: These styles are now managed globally in global-fields.css with Filament color #16A34A */
/* Keeping this for backward compatibility but global-fields.css takes precedence */
#search:focus {
    border-color: var(--tickets-select2-accent) !important;
    outline: none !important;
    box-shadow: 0 0 0 1px var(--tickets-select2-accent) !important;
}

.dark #search:focus {
    border-color: var(--tickets-select2-accent) !important;
    outline: none !important;
    box-shadow: 0 0 0 1px var(--tickets-select2-accent) !important;
}

/* Dark mode hover and focus styles are now managed globally in global-fields.css */

/* Tickets list filters: at most 3 Select2 fields per row; column count still follows container width */
#tickets-list-filters-select2-grid {
    display: grid;
    width: 100%;
    min-width: 0;
    margin-top: 0.75rem;
    gap: 1rem;
    /* Min track = one-third of row (minus 2 gaps) or 13rem, so a 4th column cannot fit */
    grid-template-columns: repeat(
        auto-fit,
        minmax(min(100%, max(13rem, calc((100% - 2rem) / 3))), 1fr)
    );
}

#tickets-list-filters-select2-grid > div {
    min-width: 0;
}

#tickets-list-filters-select2-grid .select2-container {
    width: 100% !important;
    max-width: 100%;
}

#projects-list-filters-select2-grid {
    --projects-filter-col: min(100%, max(13rem, calc((100% - 2rem) / 3)));
    display: grid;
    width: 100%;
    min-width: 0;
    margin-top: 0.75rem;
    gap: 1rem;
    grid-template-columns: repeat(
        auto-fit,
        minmax(var(--projects-filter-col), var(--projects-filter-col))
    );
}

#projects-list-filters-select2-grid > div {
    min-width: 0;
}

#projects-list-filters-select2-grid .select2-container {
    width: 100% !important;
    max-width: 100%;
}

/* Edit / relation drawer: native select height matches Select2; dropdown mounts on .edit-drawer-root */
.edit-drawer-root select.drawer-select2:not(.select2-hidden-accessible) {
    min-height: 42px;
    box-sizing: border-box;
}

.edit-drawer-root .select2-dropdown {
    z-index: 50;
}

/* Time logs list header: collaborator Select2 — compact height (match previous text-sm + py-1.5 toolbar select) */
.timelog-header-collaborator-s2-wrap {
    width: 11rem;
    max-width: 11rem;
}

@media (min-width: 640px) {
    .timelog-header-collaborator-s2-wrap {
        width: 14rem;
        max-width: 14rem;
    }
}

.timelog-header-collaborator-s2-wrap .select2-container {
    width: 100% !important;
    max-width: 100%;
}

#select2-timelog_header_collaborator_select2-container.select2-container--default .select2-selection--single {
    height: 36px;
    min-height: 36px;
    border-radius: 0.375rem;
}

#select2-timelog_header_collaborator_select2-container.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 34px;
    font-size: 0.875rem;
    padding-left: 0.5rem;
    padding-right: 1.75rem;
}

#select2-timelog_header_collaborator_select2-container.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 34px;
    right: 0.35rem;
}

.dark #select2-timelog_header_collaborator_select2-container.select2-container--default .select2-selection--single {
    background-color: rgb(31 41 55);
    border-color: rgb(75 85 99);
}

.dark #select2-timelog_header_collaborator_select2-container.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: rgb(243 244 246) !important;
}
