/* Admin overrides to make text selection visible and re-enable selection inside Select2 widgets.
   Placed in a dedicated file so it survives regeneration of other admin static files.
*/

/* Allow selection inside select2 components (they set user-select: none) */
.select2-container .select2-selection--single,
.select2-container .select2-selection--single .select2-selection__rendered,
.select2-container .select2-selection--multiple,
.select2-container .select2-results__option {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
}

/* Make selection highlight visible inside admin/grappelli inlines and note areas */
.grp-module ::selection,
.grp-module ::-moz-selection,
.grappelli ::selection,
.grappelli ::-moz-selection,
.grp-table ::selection,
.grp-tr ::selection,
.grp-td ::selection,
.grp-th ::selection,
.grp-collapse ::selection,
.wrap_lines ::selection,
.note_text ::selection {
    background: #b3d4fc; /* light blue - readable and similar to browser default */
    color: #000;
}

/* Strong override for Grappelli inline selection rules that set background: transparent
   (matches both forms with and without a space before ::selection for safety) */
.grp-collapse::selection,
.grp-collapse ::selection,
.grp-collapse .grp-row::selection,
.grp-collapse .grp-row ::selection,
.grp-collapse .grp-collapse-handler::selection,
.grp-collapse .grp-collapse-handler ::selection,
.grp-collapse .grp-td::selection,
.grp-collapse .grp-td ::selection,
.grp-table ::selection,
.grp-tr ::selection,
.grp-td ::selection,
.grp-th ::selection,
.wrap_lines ::selection,
.note_text ::selection {
    background: #3064ce !important; /* visible light-blue */
    color: #FFFFFF !important;
}

/* Ensure admin container descendants show visible selection and override other rules (very specific) */
#grp-container *::selection, #grp-container *::-moz-selection {
    background: #3064ce !important;
    color: #FFFFFF !important;
}

/* Also ensure CKEditor note areas inside notes use readable selection */
.note_text, .wrap_lines, .grp-td {
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

/* Switch encounters inline to CSS grid so the note row can span all columns.
   CSS tables have no colspan equivalent for non-<table> elements — a plain div
   inside table-row-group is forced into an anonymous single-column cell.
   With grid + display:contents on the intermediate wrappers, every cell and the
   note div become direct grid items; grid-column:1/-1 then spans the full row. */
#encounters-group .grp-module.grp-table {
    display: grid !important;
    grid-template-columns: auto auto auto auto auto auto auto;
    row-gap: 2px;
    width: 100%;
}
/* Header cells become direct outer-grid items */
#encounters-group .grp-module.grp-table .grp-thead,
#encounters-group .grp-module.grp-table .grp-tr {
    display: contents !important;
}
/* Each encounter is a real box spanning all columns and mirroring the outer column tracks.
   row-gap:0 keeps the note row flush against the cells above it;
   the outer row-gap between grp-tbody boxes provides the inter-encounter spacing. */
#encounters-group .grp-module.grp-table > .grp-tbody {
    display: grid !important;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    row-gap: 0;
    margin: 0;
}
#encounters-group .grp-module.grp-table .grp-th,
#encounters-group .grp-module.grp-table .grp-td {
    display: block !important;
    height: auto !important;
    border-bottom: none !important;
    overflow: visible !important;
}

/* Encounters without a note need their own bottom border for visual closure */
#encounters-group .grp-module.grp-table > .grp-module:not(:has(.encounter-note-row)) .grp-td {
    border-bottom: 1px solid #ccc !important;
}

/* Kill Grappelli's float+negative-top trick on the tools cell.
   grp-tools sits on both the cell div and inner ul, so we target the cell
   via a dedicated class added in encounter_inline.html. */
#encounters-group .encounter-tools-cell{
    position: static !important;
    float: none !important;
    margin: 0 !important;
}


/* Full-width note row that spans all columns in the encounters grid */
.encounter-note-row {
    grid-column: 1 / -1;
    white-space: normal;
    padding: 7px 12px 6px;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    background-color: #eee;
    color: #444;
    box-sizing: border-box;
    font-size: 0.9em;
}

/* Restore rich-text formatting inside encounter notes (admin CSS resets these globally) */
.encounter-note-row ol,
.encounter-note-row ul {
    list-style: revert;
    margin: 0.4em 0 0.4em 1.5em;
    padding: 0;
}
.encounter-note-row ol {
    list-style-type: decimal;
}
.encounter-note-row ul {
    list-style-type: disc;
}
.encounter-note-row li {
    display: list-item;
}
.encounter-note-row table {
    border-collapse: collapse;
    margin: 0.4em 0;
}
.encounter-note-row table td,
.encounter-note-row table th {
    border: 1px solid #bbb;
    padding: 3px 7px;
}
