/* Report tables (DataTables): fit rules a table opts into. 2026-11-12, see docs/datatables-layout.md.

   Why: theme.css gives every Semantic table `table-layout: fixed`, and DataTables 1.10 pins each column (and the
   table) to the pixel width it measured when the page loaded. A long email, an unbroken name or a row of buttons that
   does not fit its frozen column then paints over the next column instead of widening its own, and nothing re-measures
   when the window or a side panel changes size.

   A table opts in with class "jw-dt" (and `autoWidth: false` when it does not scroll; see the doc). It gets the
   browser's automatic layout back, and its columns say what they hold, through `data-class-name` on the <th> so every
   cell of the column carries it (rows added later too):
     jw-dt-text      names, emails, notes: wrap; a long unbroken value breaks inside its own cell
     jw-dt-atom      IDs, phone numbers, amounts, dates, PINs: never broken, the column makes room
     jw-dt-badges    pills / status / role chips: flow onto more lines
     jw-dt-actions   a cell of buttons, wrapped in <span class="jw-dt-actgroup">: wraps inside its cell,
                     two buttons wide at the least
     jw-dt-center    centred (instead of an inline text-align, which the card layout could not undo)
   "jw-dt-stack" as well: when the table cannot fit its report, or under 768px where Semantic UI already stacks every
   table, assets/js/report-tables.js adds "jw-dt-stacked" and the rows become labelled cards; the headings stay as a
   row of sort buttons. Nothing is hidden and no control is copied. Nothing here touches a table that has not opted in. */

table.ui.table.jw-dt { table-layout: auto; }

table.jw-dt > tbody > tr > td.jw-dt-text {
	white-space: normal;
	overflow-wrap: anywhere;
	word-break: normal;
	min-width: 6em;
}
@supports not (overflow-wrap: anywhere) {
	table.jw-dt > tbody > tr > td.jw-dt-text { word-break: break-word; }
}
table.jw-dt > tbody > tr > td.jw-dt-atom,
table.jw-dt > thead > tr > th.jw-dt-atom { white-space: nowrap; }
table.jw-dt > tbody > tr > td.jw-dt-badges { white-space: normal; }
table.jw-dt > tbody > tr > td.jw-dt-actions { white-space: normal; }
table.jw-dt > tbody > tr > td.jw-dt-center,
table.jw-dt > thead > tr > th.jw-dt-center { text-align: center; }
table.jw-dt .jw-dt-actgroup {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-width: 94px; /* two 44px buttons and the gap */
}
table.jw-dt td.jw-dt-actions:not(.jw-dt-center) .jw-dt-actgroup { justify-content: flex-start; }

/* The DataTables wrapper is a Semantic grid: its columns are flex items, which will not shrink below their content, so
   a wide table used to drag the whole report past the card. Let them shrink; the table decides how to fit.
   (The Semantic `dom` builds div.dataTables_wrapper > div.ui.grid > div.row > div.column.) */
.dataTables_wrapper.jw-dt-wrap > .ui.grid > .row > .column { min-width: 0; }
.dataTables_wrapper.jw-dt-wrap .dataTables_paginate .ui.pagination.menu { flex-wrap: wrap; max-width: 100%; }
/* A narrow report: export / search / length / paging each take the full width (beating Semantic's
   `.ui.grid > .row > [class*="eight wide"].column { width: 50% !important }`). */
.dataTables_wrapper.jw-dt-wrap.jw-dt-narrow > .ui.grid > .row > .column { width: 100% !important; text-align: left !important; }
.dataTables_wrapper.jw-dt-wrap.jw-dt-narrow > .ui.grid > .row > .column + .column { padding-top: 0 !important; }
.dataTables_wrapper.jw-dt-wrap.jw-dt-narrow .dataTables_filter,
.dataTables_wrapper.jw-dt-wrap.jw-dt-narrow .dataTables_filter label,
.dataTables_wrapper.jw-dt-wrap.jw-dt-narrow .dataTables_filter .ui.input,
.dataTables_wrapper.jw-dt-wrap.jw-dt-narrow .dataTables_filter input { width: 100% !important; min-width: 0 !important; }
.dataTables_wrapper.jw-dt-wrap.jw-dt-narrow .dataTables_filter label { display: block; }

/* The card layout. Semantic UI's own mobile rule (under 768px) sets the same rows and cells to display:block with
   !important, so these restate it with !important where they have to win (the header row as wrapping sort buttons). */
@media screen {
	table.ui.table.jw-dt.jw-dt-stacked { display: block; width: 100% !important; border: 0; background: transparent; }
	table.ui.table.jw-dt.jw-dt-stacked > thead,
	table.ui.table.jw-dt.jw-dt-stacked > tbody,
	table.ui.table.jw-dt.jw-dt-stacked > tfoot { display: block !important; width: auto !important; }
	table.ui.table.jw-dt.jw-dt-stacked > thead > tr {
		display: flex !important;
		flex-wrap: wrap;
		gap: 6px;
		padding: 0 0 12px !important;
		box-shadow: none !important;
	}
	table.ui.table.jw-dt.jw-dt-stacked > thead > tr > th {
		display: block !important;
		flex: 0 0 auto;
		width: auto !important;
		max-width: 100%;
		border: 1px solid #e2e8f0 !important;
		border-radius: 999px !important;
		white-space: nowrap;
	}
	table.ui.table.jw-dt.jw-dt-stacked > thead > tr > th:empty { display: none !important; }
	table.ui.table.jw-dt.jw-dt-stacked > tbody > tr {
		display: block !important;
		margin: 0 0 12px;
		padding: 4px 0 !important;
		border: 1px solid #e5e7eb;
		border-radius: 14px;
		background: #fff;
		box-shadow: none !important;
	}
	table.ui.table.jw-dt.jw-dt-stacked > tbody > tr > td,
	table.ui.table.jw-dt.jw-dt-stacked > tfoot > tr > td,
	table.ui.table.jw-dt.jw-dt-stacked > tfoot > tr > th {
		display: block !important;
		width: auto !important;
		text-align: left !important;
		border: 0 !important;
		box-shadow: none !important;
	}
	table.ui.table.jw-dt.jw-dt-stacked > tbody > tr > td:empty,
	table.ui.table.jw-dt.jw-dt-stacked > tfoot > tr > td:empty,
	table.ui.table.jw-dt.jw-dt-stacked > tfoot > tr > th:empty { display: none !important; }
	table.ui.table.jw-dt.jw-dt-stacked > tfoot > tr { display: block !important; padding: 0 !important; box-shadow: none !important; }
	table.ui.table.jw-dt.jw-dt-stacked > tbody > tr > td[data-label]:not([data-label=""])::before,
	table.ui.table.jw-dt.jw-dt-stacked > tfoot > tr > td[data-label]:not([data-label=""])::before {
		content: attr(data-label);
		display: block;
		margin: 0 0 3px;
		font-size: .72rem;
		font-weight: 700;
		line-height: 1.3;
		letter-spacing: .04em;
		text-transform: uppercase;
		color: #64748b;
	}
	table.ui.table.jw-dt.jw-dt-stacked .jw-dt-actgroup { justify-content: flex-start; }
}
