/*
	Devices data grid (#179).

	Scoped entirely under #device-table.device-grid / .device-table-scroll so
	nothing here leaks into other pages. main.css sets global element rules
	(table { display: block }, td/th { display: inline-block }) that destroy
	real table layout, so this file explicitly restores table display roles
	for the grid. Colors come from the shared theme tokens in main.css, which
	the html[data-theme='dark'] overrides retarget automatically.
*/

.device-table-scroll {
	overflow-x: auto;
	width: 100%;
}

#device-table.device-grid {
	display: table;
	width: 100%;
	min-width: 82rem;
	table-layout: auto;
	border-collapse: separate;
	border-spacing: 0;
	background: var(--color-surface);
	border: 1px solid var(--color-border);
	border-radius: 0.5rem;
	overflow: hidden;
	margin: 0 0 1rem 0;
}

#device-table.device-grid thead {
	display: table-header-group;
}

#device-table.device-grid tbody {
	display: table-row-group;
}

#device-table.device-grid tr {
	display: table-row;
	background: transparent;
}

#device-table.device-grid th,
#device-table.device-grid td {
	display: table-cell;
	vertical-align: middle;
	text-align: left;
	padding: 0.3rem 0.35rem;
	border-bottom: 1px solid var(--color-divider);
}

#device-table.device-grid thead th {
	position: sticky;
	top: 0;
	z-index: 2;
	background: var(--color-surface-muted);
	color: var(--color-text-primary);
	font-weight: bold;
	font-size: 0.85rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	white-space: nowrap;
	border-bottom: 2px solid var(--color-border);
}

#device-table.device-grid thead th abbr {
	text-decoration: none;
	border-bottom: none;
	cursor: help;
}

/* Sortable headers: the button inherits the header look; the indicator is
   drawn from aria-sort so the visual state can never disagree with what
   assistive tech is told. */
.device-grid__sort-button {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	letter-spacing: inherit;
	text-transform: inherit;
	cursor: pointer;
}

.device-grid__sort-button::after {
	content: '\2195';
	font-size: 0.75em;
	opacity: 0.45;
}

#device-table.device-grid thead th[aria-sort='ascending'] .device-grid__sort-button::after {
	content: '\2191';
	opacity: 1;
}

#device-table.device-grid thead th[aria-sort='descending'] .device-grid__sort-button::after {
	content: '\2193';
	opacity: 1;
}

.device-grid__sort-button:focus-visible {
	outline: 2px solid var(--color-link);
	outline-offset: 2px;
}

#device-table.device-grid tbody tr:nth-child(even) {
	background: var(--color-surface-muted);
}

#device-table.device-grid tbody tr:hover {
	background: var(--color-overlay);
}

/* A row with input warnings listed under the grid (#222). Same specificity
   as the stripe and hover rules above and declared after them, so the
   highlight wins on an even row and stays under the pointer. */
#device-table.device-grid tbody tr.device-grid__row--warning {
	background: var(--color-warning-bg);
}

/* A row armed for deletion, waiting out its undo window (#373). Declared
   AFTER the warning rule at equal specificity so an armed row reads as armed
   even when it also has input warnings -- the pending state is the one the
   operator has seconds to act on. The row is still in the model and still
   persisted; this says "about to go", not "gone". */
#device-table.device-grid tbody tr.device-grid__row--pending-deletion {
	background: var(--color-error-bg);
	opacity: 0.6;
	text-decoration: line-through;
	/* The strike marks the row; controls inside it stay legible. */
	text-decoration-color: var(--color-error-text);
}

#device-table.device-grid tbody tr.device-grid__row--pending-deletion .device-grid__input,
#device-table.device-grid tbody tr.device-grid__row--pending-deletion select {
	text-decoration: none;
}

#device-table.device-grid tbody tr:last-child th,
#device-table.device-grid tbody tr:last-child td {
	border-bottom: none;
}

/* Order column */
.device-grid__cell--order {
	text-align: center;
	min-width: 7rem;
}

.device-grid__order-controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.25rem;
	flex-wrap: nowrap;
}

.device-grid__drag-handle {
	flex: 0 0 auto;
	display: inline-block;
	color: var(--color-text-secondary);
	cursor: grab;
	user-select: none;
	vertical-align: middle;
}

.device-grid__drag-handle:active {
	cursor: grabbing;
}

.device-grid__row--dragging {
	opacity: 0.55;
}

/* Doubled class so this width beats .device-grid__input's width:100%,
   which is declared later in the file at equal specificity. */
.device-grid__input.device-grid__order-input {
	flex: 0 0 auto;
	width: 2.8rem;
	text-align: center;
	appearance: textfield;
	-moz-appearance: textfield;
}

.device-grid__order-input::-webkit-outer-spin-button,
.device-grid__order-input::-webkit-inner-spin-button {
	appearance: none;
	margin: 0;
}

.device-grid__delete-row {
	flex: 0 0 auto;
	display: inline-block;
	padding: 0 0.35rem;
	border: 1px solid transparent;
	border-radius: 0.3rem;
	background: transparent;
	color: var(--color-text-secondary);
	font-size: 1rem;
	line-height: 1.4;
	cursor: pointer;
	vertical-align: middle;
}

.device-grid__delete-row:hover,
.device-grid__delete-row:focus-visible {
	color: var(--color-error-text);
	background: var(--color-error-bg);
	border-color: var(--color-error-border);
}

.device-grid__delete-row:focus-visible {
	outline: 2px solid var(--color-link);
	outline-offset: 1px;
}

.device-grid__delete-row[disabled] {
	opacity: 0.4;
	cursor: not-allowed;
}

/* Inputs */
.device-grid__input {
	box-sizing: border-box;
	width: 100%;
	padding: 0.28rem 0.3rem;
	border: 1px solid var(--color-control-border);
	border-radius: 0.3rem;
	background: var(--color-control-bg);
	color: var(--color-control-text);
	font: inherit;
	font-size: 0.9rem;
	line-height: 1.2;
}

.device-grid__input:focus-visible {
	outline: 2px solid var(--color-link);
	outline-offset: 1px;
}

.device-grid__input[disabled] {
	background: var(--color-surface-muted);
	color: var(--color-text-secondary);
	border-color: var(--color-divider);
	cursor: not-allowed;
	opacity: 0.7;
}

.device-grid__input--select {
	appearance: auto;
}

/* Column widths: enough for the content, no more; the wrapper scrolls when
   the viewport cannot fit the sum. */
.device-grid__cell--serial { min-width: 5.8rem; }
.device-grid__cell--type { min-width: 5.2rem; }
.device-grid__cell--location { min-width: 8rem; }
.device-grid__cell--start-date,
.device-grid__cell--end-date { min-width: 7.6rem; }
.device-grid__cell--start-time,
.device-grid__cell--end-time { min-width: 5.9rem; }
.device-grid__cell--initial-voltage,
.device-grid__cell--final-voltage { min-width: 4.6rem; }
.device-grid__cell--results { min-width: 8.5rem; }
.device-grid__cell--average { min-width: 7rem; }
.device-grid__cell--field-blank { min-width: 3.8rem; text-align: center; }

/* Results pill */
.device-grid__result {
	display: inline-flex;
	align-items: baseline;
	gap: 0.3rem;
	padding: 0.25rem 0.6rem;
	border-radius: 1rem;
	background: var(--color-accent);
	color: var(--color-text-inverse);
	white-space: nowrap;
}

.device-grid__result-value {
	font-weight: bold;
	font-size: 0.95rem;
}

.device-grid__result-uncertainty {
	font-size: 0.8rem;
	opacity: 0.9;
}

.device-grid__result-units {
	font-size: 0.8rem;
	opacity: 0.9;
}

/* Location average: quieter than the result pill -- it is derived context,
   not a per-device measurement. */
.device-grid__average {
	color: var(--color-text-secondary);
	font-size: 0.85rem;
	white-space: nowrap;
}

.device-grid__field-blank-checkbox {
	width: 1.05rem;
	height: 1.05rem;
	margin: 0;
	vertical-align: middle;
	cursor: pointer;
	accent-color: var(--color-accent);
}

.device-grid__field-blank-checkbox[disabled] {
	cursor: not-allowed;
	opacity: 0.5;
}
