@layer components {

/* ── Aegis Table (ported from data-display-table--guidelines) ──
 * Native <table> styling. Wrap in .ds-table-wrap for the rounded-card
 * + shadow effect. Two densities (default / --small), optional
 * checkbox column, optional zebra rows, optional footer with
 * pagination controls. */
.ds-table-wrap {
  background: var(--color-bg-surface);
  /* Stretched flat (no border / radius / shadow). MODEC's list tables
   * sit flush with the page surface. Opt-in card look via .ds-table-
   * wrap--card if a consumer wants the elevated visual back. */
  width: 100%;
}
.ds-table-wrap--card {
  border-radius: var(--radius-md);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 1px 4px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}
.ds-table-wrap--scroll { overflow-x: auto; }
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-family-sans);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  background: var(--color-bg-surface);
}
.ds-table thead th {
  position: relative;
  padding: 14px 32px 14px 16px;  /* extra right padding reserves space for hover sort arrow */
  text-align: left;
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  background: var(--color-bg-surface);
  border-bottom: var(--border-width-1) solid var(--color-divider);
  white-space: nowrap;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}
/* Vertical divider between consecutive header cells (MODEC look) — drawn
 * with a ::before pseudo so it can be shorter than the cell, with gaps at
 * top and bottom so it never touches the row's horizontal divider line. */
.ds-table thead th:not(:last-child)::before {
  content: "";
  position: absolute;
  right: 0;
  top: 25%;
  bottom: 25%;
  width: 1px;
  background: var(--color-border-subtle);
  pointer-events: none;
}
/* Sort affordance — up-arrow appears on hover at the right edge of every th.
 * Permanently shown (full opacity) when the column carries .is-sorted-asc
 * or .is-sorted-desc (the latter flips the arrow with a 180° rotate). */
.ds-table thead th::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  width: 16px;
  height: 16px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23616161' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5M5 12l7-7 7 7'/%3E%3C/svg%3E")
    center / contain no-repeat;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity 0.15s ease, transform 0.2s ease;
  pointer-events: none;
}
.ds-table thead th:hover { color: var(--color-accent); }
.ds-table thead th:hover::after { opacity: 0.7; }
.ds-table thead th.is-sorted-asc::after { opacity: 1; }
.ds-table thead th.is-sorted-desc::after {
  opacity: 1;
  transform: translateY(-50%) rotate(180deg);
}
/* Opt-out modifier for columns that are intentionally non-sortable
 * (e.g. action icon columns, checkbox column). */
.ds-table thead th.is-not-sortable {
  cursor: default;
}
.ds-table thead th.is-not-sortable:hover { color: var(--color-text-primary); }
.ds-table thead th.is-not-sortable::after,
.ds-table thead th.is-not-sortable:hover::after { opacity: 0; }

/* ── Column filter (opt-in via `.ds-table--filterable` on the table) ──
 * `public/shared/ds-table-filter.js` injects a small filter-icon <button>
 * inside every eligible th. Sits absolute-positioned right next to the
 * sort arrow on the column's right edge (Image #187 spec): funnel at
 * `right: 28px`, sort arrow at `right: 8px`. The 48px right-padding on
 * filterable th's reserves space for both so column text never bleeds
 * under either icon. */
.ds-table--filterable thead th {
  padding-right: 48px;             /* sort arrow at right:8 (16px wide) + filter at right:28 (18px wide) */
}
.ds-table__filter-btn {
  position: absolute !important;                 /* defeat base `button { position: relative }` */
  right: 28px !important;                        /* sits to the left of the sort arrow (right:8) */
  top: 50% !important;
  margin-top: -9px !important;                   /* half of 18px height for vertical centering — avoids transform stacking-context interaction with parent (Image #188 had funnel rendering above the row when translateY was being clipped) */
  width: 18px !important;
  height: 18px !important;
  padding: 0 !important;                         /* base button rule sets 10px 20px — kill it */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;                   /* base `button { box-shadow: 0 1px 2px … }` was painting a card edge around the icon (Image #185) */
  color: rgba(0, 0, 0, 0.54);
  cursor: pointer;
  border-radius: 50%;                            /* matches MUI IconButton hover-ring shape */
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.ds-table--filterable thead th:hover .ds-table__filter-btn { opacity: 0.7; }
.ds-table__filter-btn:hover {
  opacity: 1 !important;
  background: rgba(0, 0, 0, 0.06) !important;    /* MUI 6%-black overlay on direct hover */
}
.ds-table__filter-btn svg { width: 14px; height: 14px; display: block; }
/* Active filter — icon sticks at full opacity in brand blue. */
.ds-table thead th.is-filter-active .ds-table__filter-btn {
  opacity: 1;
  color: var(--color-accent);
}
.ds-table thead th.is-not-filterable .ds-table__filter-btn { display: none; }

/* Filter-hidden rows (set by ds-table-filter.js). Coordinates with the
 * pagination helper, which excludes these rows from its allRows() count. */
.ds-table tbody tr[data-filter-hidden="1"] { display: none; }

/* ── Filter popover (rendered at document root, fixed-positioned) ──
 * Layout matches MODEC reference: rounded search field, Select All on its
 * own row with a single divider below it, value list packed flush, Title-
 * Case Close/Apply on the footer. */
.ds-table__filter-popover {
  position: fixed;
  z-index: 10005;
  width: 300px;
  max-width: calc(100vw - 32px);
  background: var(--color-bg-surface);
  border-radius: 8px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.10),
    0 2px 4px  rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  /* MODEC body1 — same as the rest of the page so labels visually match. */
  font-family: "Noto Sans", sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.15px;
  color: rgba(0, 0, 0, 0.87);
  overflow: hidden;
  animation: ds-table-filter-in 0.12s ease-out;
}
.ds-table__filter-search {
  padding: 14px 14px 8px;
}
.ds-table__filter-search input {
  width: 100% !important;
  background: var(--c-neutral-100) !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 10px 14px !important;
  font-family: inherit !important;
  font-size: 16px !important;
  font-weight: 400 !important;
  line-height: 1.5 !important;
  letter-spacing: 0.15px !important;
  color: rgba(0, 0, 0, 0.87) !important;
  outline: none !important;
  box-shadow: none !important;
}
.ds-table__filter-search input::placeholder { color: rgba(0, 0, 0, 0.42); }
.ds-table__filter-list {
  max-height: 280px;
  overflow-y: auto;
}
/* `!important` on display/margin/padding/font overrides the global
 * `label { display: block; margin-top: 16px; font-weight: semibold; ... }`
 * rule in styles.css (in @layer features, which beats @layer components
 * for non-important — but !important in components beats non-important
 * in features).
 *
 * Box model matches the MODEC reference: margin 0, border 0,
 * padding 4 / 16 / 4 / 16 → option row renders at 268×32. */
.ds-table__filter-option {
  display: flex !important;
  align-items: center;
  gap: 16px;                          /* spacing between checkbox and label */
  margin: 0 !important;               /* reset the global label margin-top: 16px */
  padding: 4px 16px !important;       /* MODEC reference: 4 top/bottom, 16 left/right */
  border: 0 !important;
  cursor: pointer;
  user-select: none;
  font: inherit;                      /* inherit MODEC body1 from popover */
  font-size: 16px !important;
  font-weight: 400 !important;        /* unbold (global label is semibold) */
  color: rgba(0, 0, 0, 0.87) !important;
}
.ds-table__filter-option:hover { background: var(--c-neutral-100); }
/* Select All sits at the top of the list (always the first item) and is
 * the ONLY option with a divider below it — separating "select all" from
 * the value rows. Value rows themselves stack flush, matching MODEC. */
.ds-table__filter-list .ds-table__filter-option:first-child {
  border-bottom: 1px solid var(--color-border-subtle);
}
.ds-table__filter-option input[type="checkbox"] {
  width: 20px !important;
  height: 20px !important;
  /* margin: 0 + the parent's `gap: 16px` produces the spacing; the
   * explicit margin-right is belt-and-suspenders against the global
   * `input, select, textarea` reset clobbering flex gaps in some
   * browsers. */
  margin: 0 4px 0 0 !important;
  padding: 0 !important;
  cursor: pointer;
  accent-color: var(--color-accent);
  flex-shrink: 0;
  vertical-align: middle;
}
.ds-table__filter-option-label {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Inherit popover's body1 typography. */
  font: inherit;
  font-weight: 400 !important;        /* unbold even if a parent forces bold */
  color: inherit;
  display: inline-flex;               /* explicit baseline alignment with checkbox */
  align-items: center;
}
.ds-table__filter-empty {
  padding: 16px 14px;
  color: rgba(0, 0, 0, 0.54);
  font-style: italic;
  font-size: 13px;
  text-align: center;
}
.ds-table__filter-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px 14px;
  gap: 8px;
}
.ds-table__filter-footer button {
  background: transparent !important;
  border: none !important;
  color: var(--color-accent) !important;
  font-family: inherit !important;
  font-size: 15px !important;
  font-weight: 500 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  cursor: pointer !important;
  padding: 6px 8px !important;
  border-radius: 4px !important;
  box-shadow: none !important;
  transition: background 0.15s ease;
}
.ds-table__filter-footer button:hover { background: rgba(63, 91, 255, 0.06) !important; }
.ds-table__filter-footer button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

@keyframes ds-table-filter-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ds-table tbody td {
  padding: 14px 16px;
  border-bottom: var(--border-width-1) solid var(--color-divider);
  vertical-align: middle;
  color: var(--color-text-primary);
}
.ds-table tbody tr:last-child td { border-bottom: none; }
.ds-table tbody tr { transition: background 0.15s ease; }
.ds-table tbody tr:hover { background: var(--color-bg-surface-alt); }
.ds-table tbody tr.is-selected { background: rgba(63, 91, 255, 0.08); }
.ds-table tbody tr.is-selected:hover { background: rgba(63, 91, 255, 0.12); }

/* Zebra rows — alternating background for legibility on dense tables */
.ds-table--zebra tbody tr:nth-child(even) { background: var(--color-bg-surface-alt); }
.ds-table--zebra tbody tr:nth-child(even):hover { background: var(--c-neutral-100); }

/* Small (dense) density */
.ds-table--small thead th,
.ds-table--small tbody td { padding: 8px 12px; font-size: var(--font-size-xs); }

/* Large (roomy) density */
.ds-table--large thead th,
.ds-table--large tbody td { padding: 20px 24px; }

/* Numeric / right-aligned columns */
.ds-table th.is-numeric,
.ds-table td.is-numeric { text-align: right; font-variant-numeric: tabular-nums; }

/* Checkbox column — narrow first column */
.ds-table th.ds-table__checkbox-col,
.ds-table td.ds-table__checkbox-col {
  width: 44px;
  padding-right: 0;
  text-align: center;
}

/* (Legacy `.is-sortable` modifier was here — now redundant. Every th is
 * sortable-looking by default; mark non-sortable columns with `.is-not-sortable`.
 * The visual sort indicator is the SVG arrow defined in the thead rule above.) */

/* Footer / pagination row — matches MUI/Aegis `TablePagination` defaults.
 *   min-height: 52px (MUI toolbar size)
 *   padding: 0 16px
 *   font-size: 14px (body2)
 *   icon buttons: 32×32
 *   colors: rgba(0,0,0,0.6) for labels, 0.87 for values
 * Three zones: rows-per-page (left), range (middle), prev/next (right).
 * Used by the `.ds-table--paginated` opt-in (see ds-table-pagination.js). */
.ds-table__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;     /* MUI default: pagination sits on the right */
  flex-wrap: wrap;
  gap: 20px;
  min-height: 52px;
  padding: 0 16px;
  font-family: var(--font-family-sans);
  font-size: 14px;                /* MUI body2 */
  color: rgba(0, 0, 0, 0.6);      /* MUI text-secondary */
  background: var(--color-bg-surface);
  border-top: var(--border-width-1) solid var(--color-divider);
}
.ds-table__footer-rows {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  white-space: nowrap;
}
/* `!important` overrides the global `input, select, textarea` reset in
 * styles.css (@layer features), which would otherwise force width:100%,
 * a 1px border, and 10/12 padding onto our compact pagination select. */
.ds-table__footer-rows [data-page-size] {
  appearance: none !important;
  -webkit-appearance: none !important;
  width: auto !important;
  background-color: transparent !important;
  border: none !important;
  border-radius: var(--radius-sm) !important;
  font-family: inherit !important;
  font-size: 14px !important;
  color: rgba(0, 0, 0, 0.87) !important;        /* MUI text-primary for value */
  cursor: pointer !important;
  padding: 2px 22px 2px 6px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1.5L5 5L9 1.5' stroke='rgba(0,0,0,0.54)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 4px center !important;
  background-size: 10px 6px !important;
  transition: background-color 0.15s ease;
}
.ds-table__footer-rows [data-page-size]:hover { background-color: rgba(0, 0, 0, 0.04) !important; }
.ds-table__footer-rows [data-page-size]:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
.ds-table__footer-range { color: rgba(0, 0, 0, 0.87); flex-shrink: 0; }
.ds-table__footer-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.ds-table__footer-nav button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: rgba(0, 0, 0, 0.54);    /* MUI default icon button color */
  cursor: pointer;
  border-radius: var(--radius-full);
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.ds-table__footer-nav button:hover { background: rgba(0, 0, 0, 0.04); color: rgba(0, 0, 0, 0.87); }
.ds-table__footer-nav button:disabled { color: rgba(0, 0, 0, 0.26); cursor: default; }
.ds-table__footer-nav button:disabled:hover { background: transparent; color: rgba(0, 0, 0, 0.26); }

/* Empty state row */
.ds-table__empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Action column — narrow last cell for an icon button (eye/inspect/etc.) */
.ds-table__action-col {
  width: 48px;
  text-align: center;
  padding-left: 0;
  padding-right: 8px;
}
/* Center-align modifier for table cells (e.g. count columns per MODEC) */
.ds-table th.is-center,
.ds-table td.is-center { text-align: center; }

.ds-table tbody tr.plans-tasks-row { cursor: pointer; }
.ds-table tbody tr.plans-tasks-row:focus-visible {
  outline: none;
  background: rgba(63, 91, 255, 0.06);
  box-shadow: inset 3px 0 0 var(--color-accent);
}

} /* end @layer components */
