/**
 * tables.css
 *
 * Table System Components
 * - Data tables with responsive behavior
 * - Table controls (search, filters, dropdowns)
 * - Bulk selection and actions
 * - Empty/loading states
 * - Pagination
 *
 * This stylesheet is loaded ONLY on dashboard pages with tables (domains, redirects, etc.)
 * to keep the main site.css lean for auth and marketing pages.
 *
 * Dependencies: Requires site.css for base button/control styles
 *
 * Architecture — the section banners below, in order (numbers are the
 * banners' own; 2 and 9 were retired — the drawer moved to drawers.css):
 * 1. Dropdown Menus · 3. Table Structure · 3a. Table Variants ·
 * 3b. Table Cell Utilities · 4. Table Controls & Filters (incl. the table
 * search) · 5. Bulk Actions Bar · 6. Table States · 7. Pagination ·
 * 8. Table-Specific Components · 10. Page-Specific Components (sync button,
 * chart host, priority stepper)
 */

/* ============================================
   1. DROPDOWN MENUS
   (Used in table filters and kebab actions)
   ============================================ */

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown__trigger {
  color: var(--text-muted);
}

.dropdown__menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: var(--menu-min);
  max-width: var(--menu-max);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: var(--space-2) 0;
  display: none;
  z-index: var(--z-dropdown, 20);
}

.dropdown__menu--align-right {
  right: 0;
}

.dropdown__menu--align-left {
  left: 0;
  right: auto;
}

/* Fit menu to trigger width (for edge-aligned dropdowns on mobile) */
.dropdown__menu--fit-trigger {
  width: 100%;
  min-width: unset;
  max-width: unset;
}

/* Auto width by widest content */
.dropdown__menu--auto {
  width: max-content;
  min-width: 100%;
}

/* A selector in a form field keeps its button's width, and its menu is as
   wide as the longest option, never narrower than the button — `--auto` for a
   `--fit-trigger` menu. Without this `.field` (a flex column) stretched the
   dropdown, and the menu, to the whole field: 527px under a 146px button. */
.field > .dropdown {
  align-self: flex-start;
  max-width: 100%;
}
.field > .dropdown > .dropdown__menu--fit-trigger {
  left: 0;
  right: auto;
  width: max-content;
  min-width: 100%;
  max-width: var(--menu-max);
}

/* Wider menu with scrolling and ellipsis — for lists of long entries
   (e.g., CF account names with email parens). Bounds prevent runaway width.
   The cap is the shared `--menu-max` too: a bare 400px beat it and ran past a
   390px phone's edge (field-dropdowns harness, 2026-11-09). */
.dropdown__menu--wide {
  /* Both bounds: a min-width larger than max-width wins, so 280px alone
     would still overflow a window under ~305px. */
  min-width: min(280px, var(--menu-max));
  max-width: min(400px, var(--menu-max));
  max-height: 320px;
  overflow: hidden auto;
}
.dropdown__menu--wide .dropdown__item {
  display: block;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.dropdown__item {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: var(--fs-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  text-align: left;
  /* A menu item can be a real link (`<a>`, so it opens in a new tab on
     Ctrl-click) — it still reads as a menu row, not as underlined text. */
  text-decoration: none;
  transition: background var(--transition-md), color var(--transition-md);
}

.dropdown__item:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  color: var(--text);
}

/* A non-pickable heading between groups of items (the project name in the
   TDS site selector). */
.dropdown__group-label {
  pointer-events: none;
  opacity: 0.6;
}
/* The currently chosen entry. Applied by every filter and selector dropdown
   (site, domain, bulk actions) but never styled, so the open menu gave no clue
   which option was already active — you had to close it and read the trigger.
   Matches the weight the language switcher already uses for the same idea.
   The wash must read stronger than hover (8%) and survive it: at 10% the two
   were hard to tell apart, and `:hover` (0,2,0) outranked the bare modifier,
   so the chosen row lost its mark under the pointer. */
.dropdown__item--selected,
.dropdown__item--selected:hover {
  font-weight: var(--fw-semibold);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
}

.dropdown__item--action {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* No `background` here: the modifier is always applied alongside base
   `.dropdown__item`, whose :hover already sets the house wash, and nothing
   competes for that property on this element. Its only deliberate difference
   on hover is the colour stepping from muted to main. Restating the wash — as
   the removed `var(--hover)` did — would just be two values free to drift. */
.dropdown__item--action:hover:not(:disabled) {
  color: var(--text-main);
}

.dropdown__item--danger {
  color: var(--danger);
}

.dropdown__item--danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* Warning actions - orange text */
.dropdown__item--warning {
  color: var(--warning);
}

.dropdown__item--warning:hover {
  background: color-mix(in srgb, var(--warning) 12%, transparent);
}

/* Cloudflare-specific actions - orange hover */
.dropdown__item--cf:hover {
  background: color-mix(in srgb, var(--accent-cf) 12%, transparent);
}

/* When both action and danger are applied, danger wins */
.dropdown__item--action.dropdown__item--danger {
  color: var(--danger);
}

.dropdown__item--action.dropdown__item--danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.dropdown__item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.dropdown--open .dropdown__menu {
  display: block;
}

/* Smart positioning: flip menu upward when near bottom of viewport */
.dropdown__menu--up {
  top: auto;
  bottom: calc(100% + var(--space-2));
}

.dropdown__menu .icon {
  width: 1rem;
  height: 1rem;
}

.dropdown__divider {
  height: 1px;
  margin: var(--space-2) 0;
  background: var(--border-subtle);
  border: none;
}

/* Status caption beside the sync chip ("applied 5 minutes ago"). Lives next to
   the trigger, not inside the menu, so it stays readable without opening it
   and does not pollute the role="menu" tree. */
.sync-caption {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Rich dropdown items (label + hint sub-elements) */
.dropdown__item--rich {
  flex-direction: column;
  align-items: flex-start;
  padding-block: var(--space-2);
}

.dropdown__item-label {
  font-weight: var(--fw-medium);
}

.dropdown__item-hint {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.dropdown__item--rich.is-active .dropdown__item-label {
  color: var(--primary);
}

/* ============================================
   3. TABLE STRUCTURE
   ============================================ */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table thead {
  background: var(--bg-soft);
}

.table th,
.table td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
}

/* The rule above is a compound selector (0,0,1,1); `.text-right`, `.text-center`
   and `.th-num` are bare classes (0,0,1,0), so inside a table they lose no matter
   where they sit in the file. That is why every numeric column in the app rendered
   left-aligned even after `.text-right` was given a definition on 2026-07-28 — the
   class existed, it just never won. Measured, not deduced: a `<td class="text-right">`
   computed to `text-align: left` on /sites, /projects and /streams.
   These pairs restore the intent at equal-or-higher specificity; `!important` is
   banned by the StyleGuide, and raising specificity is the sanctioned fix. */
.table th.text-right,
.table td.text-right,
.table th.th-num,
.table td.th-num {
  text-align: right;
  /* Digits share one advance width, so amounts line up column-wise instead of
     drifting with the glyphs. Scoped to tables: elsewhere `.text-right` is prose. */
  font-variant-numeric: tabular-nums;
}

.table th.text-center,
.table td.text-center {
  text-align: center;
}

.table th {
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

/* Sortable table header button. Wired 2026-08-12 via src/ui/table-sort.ts
   (domains, sites, projects, integrations) — recipe in StyleGuide → Tables.
   Merged 2026-08-01 from two full declarations ~700 lines apart, which disagreed
   on nine properties and on the hover colour (--text here, --brand there). The
   later one won, so everything in this block was dead — and since the component
   was wired to zero tables back then, nobody could have noticed.
   Values below are the ones that actually rendered. */
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.th-sort:hover {
  color: var(--brand);
}

/* Direction indicator: dim two-way arrow at rest, full-color chevron when the
   column is active. State lives in aria-sort on the <th> (set by
   src/ui/table-sort.ts), so CSS keys off the attribute instead of a class. */
.th-sort .icon {
  width: 1em;
  height: 1em;
  opacity: 0.45;
}

th[aria-sort] .th-sort {
  color: var(--brand);
}

th[aria-sort] .th-sort .icon {
  opacity: 1;
}

.table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
}

.table tbody tr:hover {
  /* Theme text colour, not white: white at 2% was zero on the light theme (301-ui#276). */
  background: color-mix(in srgb, var(--text) 4%, transparent);
}

/* Admin lists are operator data tables, six to eight columns of figures: a
   tighter inline padding (space-2, not space-3) is what lets the Russian
   headers fit the card at desktop width (measured 2026-10-06). Compound
   selector on purpose — it must outrank `.table th, .table td`. */
.table.table--admin th,
.table.table--admin td {
  padding-inline: var(--space-2);
}

/* The record just saved on an editor screen, back in its list (StyleGuide
   "Editor Screen"): a primary wash that fades out. The fade is the whole
   signal, so it ends transparent rather than holding a second "selected" look.
   No fill mode: once it ends, hover is the row's own again. */
.table tbody tr.is-just-saved {
  animation: row-just-saved 3s ease-out;
}

@keyframes row-just-saved {
  from { background: color-mix(in srgb, var(--primary) 18%, transparent); }
  to { background: transparent; }
}

/* A row that opens its record (admin lists, src/admin/table.ts). The open
   button in the actions cell stays: the row itself is not focusable. */
.table--open-rows tbody tr {
  cursor: pointer;
}

/* A row's ⋯ menu opens inside .table-scroll, whose overflow-x: auto clips on
   BOTH axes — on a two-row table the menu showed one item of three. Admin
   tables are held to fit their container (tests/harness/admin-widths.mjs), so
   while a menu is open the scroller can show its overflow without losing a
   horizontal scroll position it never had. Client tables can be wider than
   their container; they keep the clip (docs/TODO-index.md). */
.table-scroll:has(> .table--admin .dropdown--open) {
  overflow: visible;
}

/* Note: .table-scroll is defined in layout.css */

/* Reduce gap between card header (filters) and adjacent body (table).
   Scoped to adjacent-sibling — cards without a header keep default body
   padding, otherwise their content would be flush with the top edge. */
.card--panel .card__header + .card__body {
  padding-top: 0;  /* Header border provides visual separation */
}

/* Compensate for card padding on mobile to prevent overflow */
@media (max-width: 1023px) {
  .card__body .table-scroll {
    margin-inline: calc(var(--card-pad-x) * -1);
    width: calc(100% + var(--card-pad-x) * 2);
  }

  /* Allow header actions to use full width */
  .card__header .card__actions {
    margin-inline: calc(var(--card-pad-x) * -1);
    padding-inline: var(--card-pad-x);
  }

  /* Prevent table search from causing overflow */
  .card__actions .table-search {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
  }

  /* Allow footer pagination to use full width */
  .card__footer .pagination {
    margin-inline: calc(var(--card-pad-x) * -1);
    padding-inline: var(--card-pad-x);
  }
}

/* ============================================
   3a. TABLE VARIANTS
   ============================================ */

/* Compact table — a small read-only breakdown (a handful of rows, no actions)
   inside a card or a `.fieldset-group`. Width follows the content; scoped as
   `.table.table--compact` so it beats `.table th, .table td` (rule 1). */
.table.table--compact {
  width: auto;
}

.table.table--compact thead {
  background: none;
}

.table.table--compact th,
.table.table--compact td {
  padding: var(--space-1) var(--space-3);
}

.table.table--compact th:first-child,
.table.table--compact td:first-child {
  padding-left: 0;
}

.table.table--compact th:last-child,
.table.table--compact td:last-child {
  padding-right: 0;
}

.table.table--compact tbody tr:last-child {
  border-bottom: none;
}

.table.table--compact tbody tr:hover {
  background: none;
}

/* Actions hug their buttons: the page tables reserve `--col-actions`, which
   in a table sized to its content is just empty width. */
.table.table--compact .th-actions,
.table.table--compact .table__cell-actions {
  width: 1%;
  white-space: nowrap;
}

/* Row headers (a label — value list): muted like a column head, but no head
   rule under each one — the row's own subtle border separates them. */
.table.table--compact tbody th {
  font-weight: var(--fw-normal);
  border-bottom: none;
}

/* Group row: names the rows below it, one line across every column. */
.table.table--compact .table__subhead th {
  padding-top: var(--space-2);
  font-weight: var(--fw-normal);
  white-space: normal;
  border-bottom: 1px solid var(--border-subtle);
}

/* Domains Table */
.table--domains {
  min-width: var(--table-min-domains);
}

/* Mobile: remove min-width to allow table to fit screen */
@media (max-width: 768px) {
  .table--domains {
    min-width: 100%;
  }
}

/* Optimize Domain column width - prevent excessive space waste */
.table--domains th:first-child,
.table--domains td:first-child {
  word-break: break-word;
  overflow-wrap: break-word;
}

/* The cap lives on the inner element, not the cell. `max-width` on a <td> under
   `table-layout: auto` is a hint the layout algorithm may ignore, and it did:
   measured on the live table, this column rendered at 300px on a roomy viewport
   and swelled to 576px as the container narrowed, so the horizontal scrollbar
   survived even after data-priority had hidden every optional column. An
   inline-block child genuinely caps its own width, so the column can no longer
   ask the table for more. Long names wrap instead of being clipped — no
   ellipsis, because the domain is the row's identity and must stay readable. */
.table--domains td:first-child > strong {
  display: inline-block;
  max-width: 220px;
  overflow-wrap: anywhere;
}

/* Status/Health centring and the Actions/Checkbox padding used to be keyed to
   `nth-child(2|3|5|6)`. Adding the Site column shifted every one of those indices
   by one, and no guard catches that — styling that depends on column ORDER is a
   landmine in a table that gains columns. Both are class-keyed now, so the next
   column can go anywhere. Centring itself moved onto `.text-center` in the
   markup (the `.table`-scoped pair is above); only padding needs a rule here. */
.table--domains th.th-actions,
.table--domains td.td-actions,
.table--domains th.th-checkbox,
.table--domains td.table__cell-checkbox {
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

/* Mobile optimizations for domains table */
@media (max-width: 768px) {
  .table th,
  .table td {
    padding: var(--space-2) var(--space-2);
  }
  /* Group and subgroup labels pad themselves (their cells have none) and must
     narrow with the cells, or their text and actions stop on a different line
     than the rows' (4px off on a phone, 2026-10-17). `.table` in front: the
     base rules sit later in this file, and a media query adds no specificity. */
  .table .table__group-label,
  .table .table__target-header {
    padding-inline: var(--space-2);
  }
  /* A positional Actions/Checkbox padding rule used to be repeated here. It was
     dead twice over: it restated the values the rule above already sets, and a
     media query adds no specificity, so the base `.table--domains` rule (0,0,2,1)
     outranked the in-media `.table th, .table td` (0,0,1,1) regardless. */
}

/* Redirects Table - auto-sizing with container queries */

/* Checkbox Column - rightmost */
.th-checkbox,
.table__th-checkbox,
.table__cell-checkbox {
  width: var(--col-check);
  text-align: center;
}

/* Same specificity trap as `.th-actions` below: the bare classes above (0,0,1,0)
   lose `text-align` to `.table th, .table td` (0,0,1,1), so this column was in
   fact centred only by the positional `nth-child(6)` rule that the Site column
   made untenable. Removing that rule without this pair would have silently
   un-centred every checkbox column in the app. */
.table th.th-checkbox,
.table th.table__th-checkbox,
.table td.table__cell-checkbox {
  text-align: center;
}

.table__cell-checkbox {
  vertical-align: middle;
}

.table__cell-checkbox .icon {
  font-size: 1.1em;
}

/* Group Header */
.table__group-header td {
  padding: 0;
  border-bottom: none;
}

/* Actions inside a group label (the TDS site row), pushed to the right edge.
   They live in the label cell, not in a cell of their own: a label spanning
   "all columns but Actions" breaks once container queries hide columns, and
   the actions then land in a column no other row has. The label pads itself
   by --space-3, as row cells do, so the buttons end on the rows' line.
   The markup reuses the rows' `.table-actions--inline`, so the gap between
   the buttons is theirs too; its `width: 100%` is undone here, and the label
   in front because that rule sits later in this file. */
.table__group-label .table__group-actions {
  width: auto;
  margin-left: auto;
}

.table__group-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-3);  /* Increased padding for better touch targets and readability */
  background: none;
  border: none;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-md);
}

.table__group-toggle:hover {
  background: color-mix(in srgb, var(--panel) 70%, var(--bg-elevated));
}

.table__group-toggle:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.table__group-toggle > .icon {
  flex-shrink: 0;
  opacity: 0.6;
}

/* ============================================
   Target Subgroup (Level 1)
   ============================================ */

.table__target-subgroup td {
  padding: 0;
  border-bottom: none;
}

.table__target-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.table__target-name {
  font-weight: var(--fw-medium);
  color: var(--text);
}

.table__target-count {
  margin-left: var(--space-1);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* ============================================
   3-Level Indentation System (Domain column only)
   ============================================ */

:root {
  --indent-unit: 1rem;  /* Base indent step (reduced for compact hierarchy) */
}

/* Level 0: Project - uses .table__group-toggle padding, no extra rule needed */

/* Level 1: Primary domains (indent 1×) - only Domain column */
.table__row--level-1 td:first-child {
  padding-left: calc(var(--space-3) + var(--indent-unit));
}

/* Mobile: Reduce indentation for compact display */
@media (max-width: 768px) {
  .table__row--level-1 td:first-child {
    padding-left: calc(var(--space-2) + var(--indent-unit) * 0.5);
  }
}

/* Column Sizing for Redirects Table */
/* Activity column (clicks) — center-align. The comment here used to say "Status",
   copy-pasted from the rule below; Status is nth-child(4). */
.table--redirects th:nth-child(3),
.table--redirects td:nth-child(3) {
  text-align: center;
}

/* Status column - center-align */
.table--redirects th:nth-child(4),
.table--redirects td:nth-child(4) {
  text-align: center;
}

/* Actions column - uses fluid token */
.table--redirects th:nth-child(5),
.table--redirects td:nth-child(5) {
  width: var(--col-actions);
}

/* Checkbox column - uses fluid token */
.table--redirects th:nth-child(6),
.table--redirects td:nth-child(6) {
  width: var(--col-check);
  text-align: center;
}

.redirect-arrow {
  font-size: 1.125rem;
  line-height: 1;
}

/* ============================================
   3b. TABLE CELL UTILITIES
   ============================================ */

.table-cell-stack {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* ============================================
   HIERARCHY CONNECTOR COMPONENT
   ============================================

   Visual hierarchy for parent-child relationships in tables.
   Uses indentation + left border to show subordination (simple, no layout shifts).

   Visual Output:
   → example.com (parent/level-1)
     | ↗ child1.com
     | ↗ child2.com
     | ↗ child3.com

   HTML Structure:
   <!-- Parent row (level-1) -->
   <div class="table-cell-stack">
     <span class="icon">→</span>
     <span class="table-cell-main">example.com</span>
   </div>

   <!-- Child rows (level-2) -->
   <div class="table-cell-stack table-cell-stack--child">
     <span class="icon">↗</span>
     <span class="table-cell-main">child1.com</span>
   </div>

   Design Tokens Used:
   - --space-2: Left margin (visual offset from parent)
   - --space-4: Left padding (content indentation)
   - --border-strong: Vertical line color (14% opacity, visible in both themes)

   Modifiers:
   - .table-cell-stack--child: Adds indentation + left border

   JS Requirements:
   - Apply .table-cell-stack--child class to child rows (level-2)
   - Pass isTopLevel=false to rendering function

   Use Cases:
   - Redirects table: donor domains under acceptor domains
   - File/folder hierarchies
   - Category/subcategory listings
   - Any parent-child table relationships

   Performance:
   - Pure CSS (no pseudo-elements, no absolute positioning)
   - No horizontal shifts (border-left doesn't affect layout width)
   - Works with collapse/expand, pagination, filtering

   ============================================ */

.table-cell-stack--child {
  padding-left: var(--space-3);
  border-left: 2px solid var(--border-strong);
  margin-left: var(--space-2);
}

.table-cell-inline {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.table-cell-main {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The row's name cell (projects, sites) and the "nothing found" row. Scoped
   to `.table td` so they outrank `.table th, .table td` (rule 1). */
.table td.table-cell-title {
  font-weight: var(--fw-medium);
}

.table td.table-cell-empty {
  padding: var(--space-6);
}

/* Empty state cell with hover quick action */
.table-cell-empty-state {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.table-cell-quick-action {
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-md);
}

tr:hover .table-cell-quick-action {
  opacity: 1;
  pointer-events: auto;
}

.table-actions--inline {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  width: 100%;
}

/* Muted Row */
.table__row--muted {
  opacity: 0.5;
}

/* Paused/Archived Site Row */
.table__row--paused {
  opacity: 0.6;
}

.table__row--paused:hover {
  opacity: 0.8;
}

.th-actions,
.table__cell-actions {
  width: var(--col-actions);
  text-align: right;
}

/* Same specificity trap as the alignment utilities above: bare classes lose to
   `.table th`, so the "Actions" heading rendered left-aligned in every table in
   the app while this rule sat here looking correct. */
.table th.th-actions,
.table td.table__cell-actions {
  text-align: right;
}

/* The TDS rules' processing-order column: a fixed narrow width, so the
   reorder arrows never shift the columns beside it. */
.th-order {
  width: var(--col-order);
}

/* Narrow numeric columns — shrink to content width */
.th-num {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

/* ============================================
   4. TABLE CONTROLS & FILTERS
   ============================================ */

/* ============================================
   STATUS BUTTON COMPONENT (Drawer)
   ============================================

   Color-coded status button with icon for binary states (enabled/disabled, active/inactive)

   HTML Structure:
   <button
     class="btn btn--sm ${enabled ? 'btn--success' : 'btn--ghost'}"
     type="button"
     data-drawer-toggle="enabled"
     data-enabled="${enabled}"
     style="border-color: ${enabled ? 'var(--ok)' : 'var(--danger)'};"
   >
     <span class="icon" data-icon="mono/${enabled ? 'check-circle' : 'close-circle'}"
           style="color: ${enabled ? 'var(--ok)' : 'var(--danger)'}"></span>
     <span>${enabled ? 'Enabled' : 'Disabled'}</span>
   </button>

   Visual States:
   - Enabled: Green border + green icon (var(--ok)) + check-circle icon
   - Disabled: Red border + red icon (var(--danger)) + close-circle icon

   JS Requirements:
   - Toggle data-enabled attribute on click
   - Update border-color, icon color, icon name, and text dynamically
   - Example: see src/redirects/drawer.ts setupToggleHandlers()

   Design Pattern:
   - Matches Redirect Code dropdown color coding (301=green, 302=yellow)
   - Provides instant visual feedback of current state
   - Border + icon color reinforce the status (redundant encoding)
   ============================================ */

/* ============================================
   TABLE SEARCH COMPONENT
   ============================================

   Unified search bar for all tables (domains, redirects, etc.)

   HTML Structure:
   <div class="table-search" data-table-search>
     <span class="icon" data-icon="mono/magnify"></span>
     <input type="text" class="table-search__input" placeholder="..." data-search-input />
     <button class="table-search__clear" type="button" aria-label="Clear" data-search-clear>
       <span class="icon" data-icon="mono/close"></span>
     </button>
   </div>

   States:
   - Default: Search icon visible, clear button hidden
   - Active (.table-search--active): Clear button visible when input has value

   JS: bindTableSearch (src/ui/table-search.ts) sets the active class and
   handles the clear button and Escape; pages never toggle it themselves.
   ============================================ */

.table-search {
  flex: 1 1 16rem;
  min-width: 0;
  border-color: var(--input-border);
  background: var(--input-bg);
  color: var(--text-main);
}

.table-search__input {
  flex: 1 1 auto;
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  line-height: inherit;
  background: transparent;
  border: 0;
  outline: none;
  width: 100%;
  color: var(--text);
  padding: 0;
}

/* Prevent iOS zoom on input focus */
@supports (-webkit-touch-callout: none) {
  .table-search__input {
    font-size: 1rem;
  }
}

/* Hide native search clear button (we use custom one) */
input[type="search"]::-webkit-search-cancel-button {
  display: none;
}

.table-search__input::placeholder {
  color: var(--muted);
}

/* Clear button - hidden by default, shown when .table-search--active */
.table-search__clear {
  display: none;  /* Hidden by default */
  border: 0;
  padding: 0;
  background: transparent;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 1.5em;
  height: 1.5em;
  flex: 0 0 1.5em;
  border-radius: 50%;
  transition: background var(--transition-fast);
}

.table-search__clear:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* Active state - show clear button when input has value */
.table-search--active .table-search__clear {
  display: inline-flex;
}

.table-search__clear .icon {
  color: var(--muted);
}

/* Table controls (filter chips) - Adaptive flex layout */
.table-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  align-content: normal;
  justify-content: flex-start;
  gap: var(--inline-gap);
}

/* Filter chips wrapper - display: contents makes children direct flex items */
.filter-chips {
  display: contents;
}

/* Domains page filter ordering: Project → Status → Health → NS → Provider → Role → Expiry.
   Every chip needs an explicit order — a chip without one gets order: 0 and
   jumps to the FRONT of the bar (how the ns chip first shipped). Project and
   site are moved up into the search row by renderFilters(); their orders here
   only matter as the fallback when that slot is missing. */
.table-controls [data-filter-id="project"] { order: 1; }
[data-domains-card] .table-controls [data-filter-id="status"] { order: 2; }
.table-controls [data-filter-id="health"] { order: 3; }
.table-controls [data-filter-id="ns"] { order: 4; }
.table-controls [data-filter-id="provider"] { order: 5; }
.table-controls [data-filter-id="role"] { order: 6; }
.table-controls [data-filter-id="site"] { order: 7; }
.table-controls [data-filter-id="expiry"] { order: 8; }

/* Redirects page filter ordering: Project → Site → Configured → Sync → Enabled */
[data-redirects-card] .table-controls [data-site-selector] { order: 2; }
.table-controls [data-filter-id="configured"] { order: 3; }
.table-controls [data-filter-id="sync"] { order: 4; }
.table-controls [data-filter-id="enabled"] { order: 5; }

/* TDS page filter ordering: Site → Type → Action → Status */
[data-tds-card] .table-controls [data-site-selector] { order: 1; }
.table-controls [data-filter-id="tds_type"] { order: 2; }
.table-controls [data-filter-id="action"] { order: 3; }
[data-tds-card] .table-controls [data-filter-id="status"] { order: 4; }

/* Override controls-row column stacking on mobile - filters can wrap horizontally */
@media (max-width: 768px) {
  .table-controls {
    flex-direction: row;
  }
}

/* Progressive filter hiding based on priority (matches column priority system) */
/* Hide low-priority filters (< 720px) */
@media (max-width: 720px) {
  .table-controls [data-priority="low"] {
    display: none;
  }
}

/* Hide medium-priority filters (< 600px) */
@media (max-width: 600px) {
  .table-controls [data-priority="medium"] {
    display: none;
  }
}

/* Hide high-priority filters on narrow screens (< 480px) */
/* Keep only critical filters visible */
@media (max-width: 480px) {
  .table-controls [data-priority="high"] {
    display: none;
  }
}

/* Default: dropdown menus align left */
.table-controls .dropdown__menu {
  left: 0;
  right: auto;
}

/* Notifications table (/notifications, 301-ui#282). The unread dot and the
   severity glyph share the first cell; the title is a button that opens the
   full text in the row below. Rules are `.table`-scoped so they outrank
   `.table td` (StyleGuide rule 1). */
.table td.notification-row__status {
  white-space: nowrap;
}

.notification-row__status .notification-icon {
  display: inline-flex;
  vertical-align: middle;
  margin-right: var(--space-1);
}

.notification-row__status > .icon {
  vertical-align: middle;
}

.notification-row__toggle {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  min-width: 0;
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.notification-row__title {
  font-weight: var(--fw-medium);
  overflow-wrap: anywhere;
}

.notification-row.is-unread .notification-row__title {
  font-weight: var(--fw-semibold);
}

.notification-row__preview {
  display: block;
  max-width: 60ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table td.notification-row__when {
  white-space: nowrap;
}

.table .notification-row__details > td {
  background: var(--bg-soft);
  padding-block: var(--space-3);
}

/* Phase 4: Priority-based progressive column hiding
 *
 * Column priority levels (set via data-priority attribute on <th> and <td>).
 * These are CONTAINER widths of .table-scroll, not viewport widths — the
 * sidebar sits between the two:
 * - critical: never hidden (Domain, Actions, Checkbox)
 * - low:      hidden at <= 690px (Expires, Created At, Notes)
 * - medium:   hidden at <= 600px (Health, Last Sync)
 * - high:     hidden at <= 480px (Status, Code, Provider)
 *
 * The numbers above were 560/720/880 in this comment while the code said
 * 480/600/720 — stale since whenever the code moved. Change both or neither.
 *
 * See StyleGuide.md section "Table Column Priorities" for full documentation.
 */

/* Container <= 690px: hide low-priority columns (Expires, Notes).
 *
 * 690, not 720, and the 30px is load-bearing. Measured on /domains: a
 * 1024-wide window gives a 734px container, and that page always has a vertical
 * scrollbar (25 rows) — so on Windows/Linux, where scrollbars are classic and
 * take 15-17px, the real container is 717-719. Against a 720 threshold the
 * Expires column was hidden on every 1024 laptop, which is the single most
 * common laptop width.
 *
 * The harness could not have caught it: headless Chromium uses overlay
 * scrollbars and reports a scrollbar width of 0, so it measured 734 and saw the
 * column. The guard for this now lives in section 9 of
 * tests/harness/domains-site-column.mjs as arithmetic rather than observation.
 *
 * Rule for the next threshold: it must clear the container of a common window
 * width by MORE than a scrollbar, or it fires for half the users and for none
 * of the tests.
 */
@container table (max-width: 690px) {
  th[data-priority="low"],
  td[data-priority="low"] {
    display: none;
  }
}

/* Admin lists (src/admin/table.ts) shed their low-priority columns earlier, at
 * 760. They carry more columns than the client tables, and the 1024 tablet
 * band gives a 734px container (717-719 with a classic scrollbar) that the
 * Accounts table needs 849 for. 760 clears both of those by more than a
 * scrollbar, and the common desktop container (862, 845 with a scrollbar)
 * stays well above it. */
@container table (max-width: 760px) {
  .table--admin th[data-priority="low"],
  .table--admin td[data-priority="low"] {
    display: none;
  }
}

/* On a phone the clipped name/email column set the table's floor: 12rem plus
   the account number left two columns 2px short of a classic scrollbar's room
   at 390px. Narrower clip there; the whole value stays in `title`. */
@container table (max-width: 480px) {
  .table--admin .text-truncate--sm {
    max-width: 9rem;
  }
}

/* Container < 600px: Hide medium-priority columns (Health, Last Sync) */
@container table (max-width: 600px) {
  th[data-priority="medium"],
  td[data-priority="medium"] {
    display: none;
  }
}

/* Container < 480px: Hide high-priority columns, keep only critical */
@container table (max-width: 480px) {
  th[data-priority="high"],
  td[data-priority="high"] {
    display: none;
  }

  /* Compact actions: hide secondary buttons, kebab only */
  .table-actions--inline .btn:not(.btn-icon) {
    display: none;
  }
}

/* Critical columns ([data-priority="critical"]) are NEVER hidden */

/* .th-sort lived here as a second full declaration and won over the one beside
   the table rules. Merged there 2026-08-01 — see the comment at that block. */

th {
  white-space: nowrap;
}

/* Controls row layout is defined in layout.css */

/* Domains page: card__actions as block container for vertical stacking */
.card__header .card__actions {
  display: block;
}

.card__header .card__actions .controls-row {
  margin-bottom: var(--space-3);
}

.card__header .card__actions .controls-row:last-child {
  margin-bottom: 0;
}

/* Search row needs flex container (domains page) */
.card__actions .controls-row:not(.table-controls) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--inline-gap);
}

.card__actions .controls-row:not(.table-controls) .table-search {
  flex: 1 1 0;
  min-width: 0;
  max-width: none;
}

/* Domains only: the search gives way to the chips beside it but never
   collapses — 12rem keeps a readable placeholder at the 1024px tablet width
   once the project chip (up to 20 truncated characters) and the site chip
   share the row. Not global: on redirects/streams the row is search + reset,
   and a floor there would fight the mobile anti-overflow rule above. */
[data-domains-card] .card__actions .controls-row:not(.table-controls) .table-search {
  min-width: 12rem;
}

/* Project + site chips in the search row (domains page). Moved out of the
   wrapping filter bar by renderFilters() so that bar keeps to one line. */
.controls-row__filters {
  display: flex;
  align-items: center;
  gap: var(--inline-gap);
  flex: 0 0 auto;
}

/* Reset button in search row */
.card__actions .controls-row .btn-icon[data-reset-filters] {
  flex: 0 0 auto;
  margin-left: var(--space-2);
  color: var(--muted);
}

/* Below the tablet width the row cannot hold search + two chips + reset, so
   the search takes the first line alone and the chips drop under it with the
   reset pinned right. Mobile keeps its progressive chip folding untouched —
   these two chips are `critical`/`high` and were never folded. Scoped to the
   domains card on purpose: redirects and streams have the same search row
   with only a reset beside the search, and an unscoped wrap would strand that
   button alone on a second line there. */
@media (max-width: 768px) {
  [data-domains-card] .card__actions .controls-row:not(.table-controls) {
    flex-wrap: wrap;
  }

  [data-domains-card] .card__actions .controls-row:not(.table-controls) .table-search {
    flex-basis: 100%;
  }

  [data-domains-card] .card__actions .controls-row .btn-icon[data-reset-filters] {
    margin-left: auto;
  }
}

/* Active state for reset button */
.btn-icon[data-reset-filters].is-active {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 10%, transparent);
  border-color: color-mix(in srgb, var(--warning) 55%, transparent);
}

.btn-icon[data-reset-filters].is-active:hover {
  background: color-mix(in srgb, var(--warning) 15%, transparent);
}

/* Collapsible filters for very small phones only */
/* Toggle button: hidden by default, visible only on tiny screens */
[data-toggle-filters] {
  display: none;
}

/* Tablets and larger: filters wrap into 2 rows naturally via grid */
/* No toggle needed, filters visible and usable */

/* Only hide filters on very small phones where even 2 columns too cramped */
@media (max-width: 480px) {
  [data-toggle-filters] {
    display: inline-flex;
    position: relative;
  }

  /* Badge on toggle button */
  [data-toggle-filters] .badge {
    position: absolute;
    top: calc(var(--space-1) * -1);
    right: calc(var(--space-1) * -1);
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 var(--space-1);
    font-size: 0.625rem;
    line-height: 1.25rem;
    border-radius: var(--radius-lg);
  }

}

/* ============================================
   5. BULK ACTIONS BAR
   ============================================ */

.bulk-actions-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-global-notice);
  /* Glassmorphism effect */
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border-strong);
  /* Upward shadow - uses canonical --shadow-md opacity (0.12 light, 0.45 dark) */
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.12);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme - uses canonical shadow opacity */
[data-theme="dark"] .bulk-actions-bar {
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.45);
}

.bulk-actions-bar:not([hidden]) {
  transform: translateY(0);
}

/* A panel opened from the bar (assign to site), under its content row. */
.bulk-actions-bar__panel {
  margin-top: var(--space-2);
  margin-bottom: var(--space-3);
}

.bulk-actions-bar__content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--inline-gap);
  padding: var(--space-3) 0;
}

.bulk-actions-bar__info {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Selection counter chip - match small button sizing */
.bulk-actions-bar__info .btn-chip {
  font-size: calc(var(--fs-control) * var(--control-scale-sm));
  padding-block: calc(var(--control-pad-y) * var(--control-scale-sm));
  padding-inline: calc(var(--control-pad-x) * var(--control-scale-sm));
  min-height: calc(var(--control-min-height) * var(--control-scale-sm));
  cursor: default;
  pointer-events: none;
}

.bulk-actions-bar__info .btn-chip .icon {
  color: var(--success);
}

/* Cancel button in info section - canonical ghost styling */
.bulk-actions-bar__info [data-bulk-cancel] {
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.bulk-actions-bar__info [data-bulk-cancel]:hover {
  background: var(--panel);
  border-color: var(--border-strong);
  color: var(--text-main);
}

/* Actions grid - follows table-controls pattern */
.bulk-actions-bar__actions {
  display: grid;
  grid-template-columns: repeat(6, auto);
  align-items: center;
  gap: var(--inline-gap);
}

/* Bulk actions buttons styling */
.bulk-actions-bar__actions .btn--ghost {
  border: 1px solid var(--brand);
  color: var(--brand);
}

.bulk-actions-bar__actions .btn--ghost:hover {
  background: var(--brand);
  color: var(--btn-text-on-dark);
}

.bulk-actions-bar__actions .btn--primary {
  background: transparent;
  border: 1px solid var(--brand);
  color: var(--brand);
}

.bulk-actions-bar__actions .btn--primary:hover {
  background: var(--brand);
  color: var(--btn-text-on-dark);
}

.bulk-actions-bar__actions .btn--danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.bulk-actions-bar__actions .btn--danger:hover {
  background: var(--danger-solid); /* white text on it — --danger fails AA on dark */
  color: var(--btn-text-on-dark);
}

.bulk-actions-bar__actions .btn--cf {
  background: transparent;
  border: 1px solid var(--accent-cf);
  color: var(--accent-cf);
}

.bulk-actions-bar__actions .btn--cf:hover {
  background: var(--accent-cf-hover);
  border-color: var(--accent-cf-hover);
  color: var(--btn-text-on-dark);
}

/* Light theme overrides - ensure brand color styling works */
html[data-theme="light"] .bulk-actions-bar__actions .btn--ghost {
  background: transparent;
  border: 1px solid var(--brand);
  color: var(--brand);
}

html[data-theme="light"] .bulk-actions-bar__actions .btn--ghost:hover {
  background: var(--brand);
  color: var(--btn-text-on-dark);
}

/* Responsive grid breakpoints - follows table-controls pattern */

/* Tablet and smaller: Cancel wraps to second row */
@media (max-width: 768px) {
  .bulk-actions-bar__info {
    /* Allow wrapping for Cancel button */
    flex-wrap: wrap;
    width: 100%;
  }
}

/* Tablet portrait: 3 columns × 2 rows */
@media (max-width: 767px) and (min-width: 481px) {
  .bulk-actions-bar__actions {
    grid-template-columns: repeat(3, auto);
  }
}

/* Mobile: 2 columns × 3 rows */
@media (max-width: 480px) {
  .bulk-actions-bar__content {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: var(--space-3);
  }

  .bulk-actions-bar__actions {
    grid-template-columns: repeat(2, 1fr);
  }

  .bulk-actions-bar__actions .btn {
    width: 100%;
  }
}

/* ============================================
   6. TABLE STATES
   ============================================ */

/* Empty State */
.empty-state {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  text-align: center;
}

/* For a small container (a popup, a card): the 400px floor is a page's. */
.empty-state.empty-state--compact {
  min-height: 0;
  padding-block: var(--space-5);
}

.empty-state .stack,
.empty-state .stack--md {
  align-items: center;
}

/* `flex: none` — `.icon` was `flex: 0 0 1em`, and in the column `.stack` that
   basis is the HEIGHT: an inline `<svg class="icon icon--lg">` has no content to
   hold it open and collapsed to 64×16 (measured 2026-10-13, 301-ui#276). `.icon`
   itself is `flex: none` since 2026-11-05; this line stays so the size never
   depends on that default again. */
.empty-state .icon--lg {
  width: 4rem;
  height: 4rem;
  flex: none;
  color: var(--text-muted);
}

.empty-state .btn-group {
  margin-top: var(--space-4);
  justify-content: center;
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: var(--space-3);
  min-height: 400px;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   7. PAGINATION
   ============================================ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--inline-gap);
}

.pagination__info {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.pagination__controls {
  display: flex;
  gap: var(--inline-gap);
}

@media (max-width: 768px) {
  .pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .pagination__controls {
    justify-content: center;
  }
}

/* ============================================
   8. TABLE-SPECIFIC COMPONENTS
   (Domain cells, provider labels, IDN indicators)
   Note: Badges moved to site.css (universal component)
   ============================================ */

/* Domain Cell Component (used in domain tables) */
.domain-cell {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  font-weight: var(--fw-medium);
}

.domain-cell__name {
  font-weight: var(--fw-semibold);
  color: var(--text);
}

/* Provider Cell (icon + label) */
.provider-cell {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

.provider-cell > .icon {
  margin-top: 0.125rem; /* Align icon with first line of text */
}

/* Provider Info Stack (name + email) */
.provider-info {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  line-height: 1.3;
}

.provider-email {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* A sub-line carrying a semantic colour must not be dimmed. --danger was
   retuned specifically to clear AA 4.5:1 (theme.css); blending it at 0.7
   over the surface drops it back to ~3.3:1, so the one line meant to raise
   an alarm would be the least legible one in the row. */
.provider-email.text-danger {
  opacity: 1;
}

/* Provider Labels (Namecheap, Namesilo, etc.) */
.provider-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  text-transform: capitalize;
}

/* Generic table cell with icon (used in projects table, sites table, etc.) */
.table-cell-with-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* Role Icon (Acceptor/Donor/Reserve) */
.role-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.role-icon[data-role="acceptor"] {
  color: var(--ok);
}

.role-icon[data-role="donor"] {
  color: var(--info);
}

.role-icon[data-role="reserve"] {
  color: var(--text-muted);
}

/* IDN Domain Display */
.domain-readable {
  /* Primary display: Unicode version */
}

.domain-punycode {
  /* Secondary display: punycode in parentheses (full mode) */
  display: inline-block;
  margin-left: 0.5ch;
  opacity: 0.7;
}

/* Subdomain hierarchy display: bold prefix + muted parent */
.domain-sub-prefix {
  font-weight: var(--fw-semibold);
}

/* TDS columns: cap widths to prevent horizontal scroll on narrow viewports */
.td-action-url {
  max-width: 160px;
}

.idn-badge {
  /* Compact badge for IDN domains in tables */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.4em;
  padding: 0.15em 0.35em;
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: help;
  transition: all var(--transition-md);
  vertical-align: middle;
}

.idn-badge .icon {
  font-size: 0.875em; /* 14px at 16px base */
}

.idn-badge:hover {
  background: var(--bg-soft);
  border-color: var(--primary);
  color: var(--primary);
}

/* Tabs component moved to site.css (core component — needed on auth/landing
   which loads site.css but not tables.css). */

/* ============================================
   10. PAGE-SPECIFIC COMPONENTS
   ============================================ */

/* --- Domains Page --- */

.expires-cell {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.provider-icon-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.provider-icon-sm .icon {
  width: 20px;
  height: 20px;
}

.health-icons {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
}

/* --- Redirects Page --- */

/* Stats Grid - responsive grid for stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

@media (min-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* Stat Card as link — clickable card without underline */
a.stat-card {
  text-decoration: none;
  color: inherit;
}

/* Stat Card - individual metric display */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: all var(--transition-md);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.stat-card__value {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: 1.2;
  color: var(--text);
}

.stat-card__label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}

/* Stat card variants with left border accent */
.stat-card--ok {
  border-left: 3px solid var(--ok);
}

.stat-card--ok .stat-card__value {
  color: var(--ok);
}

.stat-card--neutral {
  border-left: 3px solid var(--text-muted);
}

.stat-card--danger {
  border-left: 3px solid var(--danger);
}

.stat-card--danger .stat-card__value {
  color: var(--danger);
}

.stat-card--primary {
  border-left: 3px solid var(--primary);
}

.stat-card--primary .stat-card__value {
  color: var(--primary);
}


/* ============================================
   Sync Status Primary Button (indicator only)
   ============================================ */

.sync-indicator-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-width: auto;
}

/* Higher contrast text/icons on primary button background */
.sync-indicator-btn .icon {
  color: rgba(255, 255, 255, 0.95);
}

/* Compact metric pill for button context.
   Double-class for higher specificity so .metric-pill { width: 100% } in
   site.css can't override this if the stylesheet load order drifts. */
.metric-pill.metric-pill--compact {
  width: calc(var(--space-6) * 3.125); /* 100px = 2rem * 3.125 */
  flex-shrink: 0;
}

.metric-pill.metric-pill--compact .metric-pill__track {
  height: calc(var(--space-2) - 2px); /* 6px = 0.5rem - 2px */
}

/* Metric pill inside primary button - high contrast for visibility */
button.btn.btn--primary.sync-indicator-btn .metric-pill__track {
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.3);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  border-radius: var(--r-pill);
}

button.btn.btn--primary.sync-indicator-btn .metric-pill__fill {
  position: absolute;
  inset: 1px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.8);
  transform-origin: left center;
  transform: scaleX(var(--metric-fill));
  transition: transform 0.3s ease;
}

/* Status-specific colors with higher specificity */
button.btn.btn--primary.sync-indicator-btn[data-status="pending"] .metric-pill__fill {
  background: var(--accent-cf);
  box-shadow: 0 0 12px var(--accent-cf);
}

button.btn.btn--primary.sync-indicator-btn[data-status="synced"] .metric-pill__fill {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.8);
}

button.btn.btn--primary.sync-indicator-btn[data-status="error"] .metric-pill__fill {
  background: var(--danger);
  box-shadow: 0 0 12px var(--danger);
}

/* Success state - green after successful sync */
button.btn.btn--primary.sync-indicator-btn[data-status="success"] .metric-pill__fill {
  background: var(--success);
  box-shadow: 0 0 12px var(--success);
}

/* Syncing animation - CF orange sweep → green success */
@keyframes cf-sync-success {
  0% {
    background: var(--accent-cf);
    transform: scaleX(0);
  }
  40% {
    background: var(--accent-cf);
    transform: scaleX(1);
  }
  70% {
    background: var(--accent-cf);
    transform: scaleX(var(--metric-fill));
  }
  100% {
    background: var(--success);
    transform: scaleX(var(--metric-fill));
  }
}

button.btn.btn--primary.sync-indicator-btn.is-syncing .metric-pill__fill {
  box-shadow: 0 0 16px var(--accent-cf);
  animation: cf-sync-success 2s ease-in-out;
}

/* Site label inside a group header. The header `td` zeroes its own padding so a
   collapsible toggle can fill the cell edge-to-edge; this row is a plain label,
   not a button, so it carries the padding itself. */
.table__group-label {
  display: flex;
  /* Centre, not baseline: the row carries buttons, and a baseline row put the
     name and badge 5px above the buttons' middle (2026-10-17). */
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  font-weight: var(--fw-medium);
}

/* Compact spinner for inline use inside a drawer — the base is 32px, which is a
 * page-level loader and dominates a form row.
 *
 * Lives here, beside `.spinner`, and not in site.css where the rest of item 24's
 * fixes went: tables.css loads AFTER site.css, so at equal specificity the base
 * width would win and the modifier would do nothing. Caught by measuring in the
 * browser, not by reading the file. */
.spinner--sm {
  width: 1.125rem;
  height: 1.125rem;
  border-width: 2px;
}

/* ============================================
   CHART HOST — where an `affiliate-charts` SVG lands

   The library draws everything inside the SVG (`src/ui/charts.ts`); the page
   only gives it room. Text and axes follow `currentColor`.

   Documented in StyleGuide → "Charts".
   ============================================ */

.chart-host {
  margin-block-start: var(--space-4);
}

.chart-host:first-child {
  margin-block-start: 0;
}

/* A flex stack spaces its children with `gap`; the margin on top of it would
   double the space (StyleGuide rule 9). The margin is for block parents —
   `.card__body`, a fieldset. */
.stack > .chart-host,
.stack-list > .chart-host {
  margin-block-start: 0;
}

.chart-host > svg {
  display: block;
}

/* ============================================
   PRIORITY STEPPER
   The reorder arrows beside a rule's priority number (TDS rules table).
   Deliberately NOT `.cluster`: that utility wraps, and in a column this narrow
   the three items broke onto two lines as a diagonal — up-arrow, number,
   down-arrow — which reads as a layout mistake rather than a control.
   ============================================ */

/* A rule the platform reports as unreachable (`shadowed_by`, 301-ui#261): it is
   in the list, visible, and never fires. Dim the name; the words live in the
   Status badge next to it. */
.table tr[data-shadowed="true"] .table-cell-main {
  color: var(--text-muted);
}

.priority-stepper {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  /* The whole point: the pair stays one unit whatever the column width. */
  flex-wrap: nowrap;
}

.priority-stepper__arrows {
  display: inline-flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Digits share one width, so 9 and 10 sit in the same column. */
.priority-stepper__number {
  font-variant-numeric: tabular-nums;
}

/* Reduced motion — last in the file so it wins by order (see the block at the
   end of site.css). The spinner keeps turning, three times slower: it is the
   only sign that something is still loading. */
@media (prefers-reduced-motion: reduce) {
  .bulk-actions-bar {
    transition: none;
  }

  /* The sync pill's own fill rule is more specific than site.css's
     `.metric-pill__fill`, so it needs its own override. */
  button.btn.btn--primary.sync-indicator-btn .metric-pill__fill {
    transition: none;
  }

  button.btn.btn--primary.sync-indicator-btn.is-syncing .metric-pill__fill {
    animation: none;
  }

  .stat-card:hover {
    transform: none;
  }

  .spinner {
    animation-duration: 2.4s;
  }
}
