/* Canonical portal data-view patterns: full-screen listings, filters, toolbars, and tables. */

/* ---------- Full-screen listing layout ---------- */

.portal-list-grid {
  --portal-list-sticky-gap: var(--portal-space-3);
  --portal-list-sticky-top: calc(var(--portal-header-height) + var(--portal-list-sticky-gap));
  display: grid;
  gap: var(--portal-space-4);
  align-items: start;
}

body.portal-list-page .portal-list-grid {
  grid-template-columns: minmax(0, var(--portal-filter-width)) minmax(0, 1fr);
  column-gap: var(--portal-list-gap);
}

body.portal-list-page.is-portal-filters-collapsed .portal-list-grid {
  grid-template-columns: 36px minmax(0, 1fr);
  column-gap: 14px;
}

body.portal-list-page.is-portal-filters-collapsed aside.portal-filter-panel {
  display: none;
}

body.portal-list-page.is-portal-filters-collapsed .portal-filter-rail-toggle:not([hidden]) {
  display: flex;
}

.portal-list-results {
  min-width: 0;
}

.portal-list-card {
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius-md);
  background: var(--portal-card);
  box-shadow: var(--portal-shadow-sm);
}

.portal-table-card {
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

/* ---------- Results headings ---------- */

.portal-page-header.header-inline,
.portal-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--portal-space-4);
}

.portal-page-header.header-inline {
  margin-bottom: var(--portal-space-3);
}

.portal-results-header {
  margin: 0 0 var(--portal-space-2);
}

.portal-results-header h2,
.portal-results-title {
  margin: 0;
  color: var(--portal-fg);
  font-size: 1.125rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.portal-results-summary {
  color: var(--portal-muted);
  font-size: 0.86rem;
}

.portal-list-header-controls,
.page-header-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--portal-space-3);
  margin-left: auto;
}

.portal-list-header-controls label,
.page-header-controls label {
  margin: 0;
}

/* ---------- Filter panels and forms ---------- */

.portal-filter-panel {
  position: sticky;
  top: var(--portal-list-sticky-top);
  padding: var(--portal-space-3);
  overflow: visible;
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius-md);
  background: var(--portal-card);
  box-shadow: var(--portal-shadow-sm);
}

.portal-filter-panel h2 {
  margin: 0 0 var(--portal-space-3);
  color: var(--portal-fg);
  font-size: 0.9rem;
  font-weight: 750;
}

.portal-filter-form {
  display: flex;
  flex-direction: column;
  gap: var(--portal-space-3);
}

.portal-filter-form .group,
.portal-filter-field {
  min-width: 0;
  margin: 0;
}

.portal-filter-form label,
.portal-filter-field > label {
  display: block;
  margin: 0 0 var(--portal-space-1);
  color: var(--portal-muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

.portal-filter-form .row,
.portal-filter-panel .row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--portal-space-2);
}

.portal-filter-panel input[type="text"],
.portal-filter-panel input[type="search"],
.portal-filter-panel input[type="date"],
.portal-filter-panel input[type="datetime-local"],
.portal-filter-panel input[type="email"],
.portal-filter-panel input[type="number"],
.portal-filter-panel input[type="tel"],
.portal-filter-panel input[type="time"],
.portal-filter-panel input[type="url"],
.portal-filter-panel select,
.portal-filter-panel textarea,
.portal-filter-panel .multiselect > button,
.portal-filter-panel .multiselect .toggle {
  width: 100%;
  min-height: var(--portal-control-height);
  padding: 8px var(--portal-control-padding-x);
  border: 1px solid var(--portal-control-border);
  border-radius: var(--portal-radius-sm);
  background: var(--portal-card);
  color: var(--portal-fg);
  font: inherit;
  font-size: 0.88rem;
}

.portal-filter-panel input:focus-visible,
.portal-filter-panel select:focus-visible,
.portal-filter-panel textarea:focus-visible,
.portal-filter-panel .multiselect > button:focus-visible,
.portal-filter-panel .multiselect .toggle:focus-visible {
  outline: none;
  border-color: var(--portal-focus-color);
  box-shadow: var(--portal-focus-ring);
}

.portal-filter-panel .multiselect {
  position: relative;
}

.portal-filter-panel .multiselect > button,
.portal-filter-panel .multiselect .toggle {
  text-align: left;
  cursor: pointer;
}

.portal-filter-panel .multiselect > button:hover,
.portal-filter-panel .multiselect .toggle:hover {
  background: var(--portal-soft-bg);
}

.portal-filter-panel .multiselect .panel {
  display: none;
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  top: calc(100% + var(--portal-space-1));
  max-height: 260px;
  padding: var(--portal-space-2);
  overflow: auto;
  border: 1px solid var(--portal-control-border);
  border-radius: var(--portal-radius-sm);
  background: var(--portal-card);
  box-shadow: var(--portal-shadow-md);
}

.portal-filter-panel .multiselect.open .panel {
  display: block;
}

.portal-filter-panel .panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--portal-space-2);
  margin-bottom: var(--portal-space-2);
}

.portal-filter-panel .list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.portal-filter-panel .list label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--portal-space-1) 2px;
  cursor: pointer;
}

.portal-filter-actions,
.portal-filter-form .actions,
.portal-filter-panel .actions {
  display: flex;
  align-items: center;
  gap: var(--portal-space-2);
  margin-top: var(--portal-space-1);
  padding-top: var(--portal-space-3);
  border-top: 1px solid var(--portal-soft-border);
}

.portal-filter-actions .btn,
.portal-filter-form .actions .btn,
.portal-filter-panel .actions .btn {
  flex: 1 1 0;
}

/* ---------- Collapsible filter rail ---------- */

.portal-filter-edge-toggle,
.portal-filter-rail-toggle {
  border: 1px solid var(--portal-border);
  background: var(--portal-card);
  color: var(--portal-fg);
  box-shadow: var(--portal-shadow-sm);
  cursor: pointer;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.portal-filter-edge-toggle {
  position: absolute;
  top: 50%;
  right: -24px;
  z-index: 2;
  width: 24px;
  height: 72px;
  padding: 0;
  transform: translateY(-50%);
  border-left: 0;
  border-radius: 0 var(--portal-radius-sm) var(--portal-radius-sm) 0;
}

.portal-filter-rail-toggle {
  display: none;
  position: sticky;
  top: var(--portal-list-sticky-top);
  align-items: center;
  justify-content: center;
  width: 100%;
  height: calc(100vh - var(--portal-header-height) - 24px);
  min-height: 220px;
  padding: 0;
  border-radius: var(--portal-radius-md);
}

.portal-filter-edge-toggle:hover,
.portal-filter-rail-toggle:hover {
  border-color: var(--portal-accent);
  background: var(--portal-soft-bg);
}

.portal-filter-edge-toggle:focus-visible,
.portal-filter-rail-toggle:focus-visible {
  outline: none;
  border-color: var(--portal-focus-color);
  box-shadow: var(--portal-focus-ring);
}

/* ---------- Inline/embedded filter bar ---------- */

.portal-filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  gap: var(--portal-space-3);
  padding: var(--portal-space-4);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius-md);
  background: var(--portal-card);
  box-shadow: var(--portal-shadow-sm);
}

.portal-filter-bar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--portal-space-2);
}

/* ---------- Table toolbar and pagination ---------- */

.portal-results-toolbar,
.toolbar,
.portal-table-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--portal-space-3);
}

.portal-results-toolbar,
.toolbar {
  margin: var(--portal-space-2) 0;
}

.portal-table-tools {
  justify-content: space-between;
  min-height: 58px;
  padding: var(--portal-space-3);
  border-bottom: 1px solid var(--portal-soft-border);
  background: var(--portal-card);
}

.portal-table-tools__start,
.portal-table-tools__end {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--portal-space-3);
}

.portal-table-tools__end {
  justify-content: flex-end;
  margin-left: auto;
}

.portal-table-tools label {
  margin: 0;
  color: var(--portal-muted);
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
}

.portal-page-size-select {
  width: 86px;
  min-height: var(--portal-control-height);
  font: inherit;
  font-size: 0.86rem;
}

.portal-pager,
.page-header-pager.case-header-paging {
  display: inline-flex;
  align-items: center;
  gap: var(--portal-space-2);
}

.portal-pager .muted,
.portal-pager__info {
  min-width: 92px;
  color: var(--portal-muted);
  text-align: center;
  font-size: 0.8rem;
  white-space: nowrap;
}

.btn.pager-btn {
  min-height: 36px;
  padding: 6px 14px;
  border-color: var(--portal-accent);
  background: var(--portal-card);
  color: var(--portal-accent);
  font-weight: 650;
}

.btn.pager-btn:hover {
  background: var(--portal-accent);
  color: #fff;
}

.btn.pager-btn:disabled,
.btn.pager-btn[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn.pager-btn:disabled:hover,
.btn.pager-btn[aria-disabled="true"]:hover {
  background: var(--portal-card);
  color: var(--portal-accent);
}

/* ---------- Full-screen data table ---------- */

.portal-table-scroll {
  position: relative;
  width: 100%;
  min-height: 280px;
  max-height: max(
    280px,
    calc(100vh - var(--portal-header-height) - var(--portal-table-scroll-offset, 180px))
  );
  overflow: auto;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  background: var(--portal-card);
}

.portal-list-table {
  width: 100%;
  min-width: var(--portal-table-min-width);
  table-layout: fixed;
  border: 0;
  border-collapse: collapse;
  color: var(--portal-fg);
  font-size: 0.9rem;
  line-height: 1.35;
}

.portal-list-table thead th {
  padding: var(--portal-table-cell-padding-y) var(--portal-table-cell-padding-x);
  border-bottom: 1px solid var(--portal-border);
  background: var(--portal-table-header-bg);
  color: rgba(17, 24, 39, 0.78);
  text-align: left;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.015em;
  line-height: 1.2;
  text-transform: none;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

.portal-table-scroll .portal-list-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 var(--portal-border);
}

.portal-list-table tbody td {
  padding: var(--portal-table-cell-padding-y) var(--portal-table-cell-padding-x);
  border-bottom: 1px solid var(--portal-soft-border);
  color: var(--portal-fg);
  vertical-align: top;
  word-break: break-word;
}

.portal-list-table tbody tr:hover td {
  background: var(--portal-table-row-hover);
}

.portal-list-table th.no-wrap,
.portal-list-table td.no-wrap,
.portal-cell--nowrap {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.portal-list-table--compact {
  --portal-table-cell-padding-y: 7px;
  --portal-table-cell-padding-x: 9px;
  font-size: 0.84rem;
}

.portal-list-table .portal-table-state {
  height: 148px;
  vertical-align: middle;
}

.portal-list-table .th-action-items {
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
}

.portal-list-table .th-action-items .th-word {
  white-space: nowrap;
}

/* Semantic column/cell utilities; page CSS owns domain widths. */

.portal-col--xs { width: 72px; }
.portal-col--sm { width: 110px; }
.portal-col--md { width: 160px; }
.portal-col--lg { width: 240px; }
.portal-col--actions { width: 132px; }

.portal-cell--numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.portal-cell--center { text-align: center; }
.portal-list-table .portal-cell--actions,
.portal-table .portal-cell--actions {
  vertical-align: middle;
}

/* ---------- Responsive behavior ---------- */

@media (max-width: 992px) {
  body.portal-list-page .portal-list-grid,
  body.portal-list-page.is-portal-filters-collapsed .portal-list-grid {
    grid-template-columns: minmax(0, 1fr);
    column-gap: 0;
  }

  body.portal-list-page aside.portal-filter-panel,
  body.portal-list-page.is-portal-filters-collapsed aside.portal-filter-panel {
    display: block;
    position: static;
    width: 100%;
  }

  body.portal-list-page .portal-filter-edge-toggle,
  body.portal-list-page .portal-filter-rail-toggle,
  body.portal-list-page.is-portal-filters-collapsed .portal-filter-rail-toggle:not([hidden]) {
    display: none;
  }
}

@media (max-width: 640px) {
  .portal-page-header.header-inline,
  .portal-results-header,
  .portal-table-tools,
  .portal-table-tools__start,
  .portal-table-tools__end {
    align-items: flex-start;
    flex-direction: column;
  }

  .portal-list-header-controls,
  .page-header-controls,
  .portal-table-tools__end {
    width: 100%;
    justify-content: flex-start;
    margin-left: 0;
  }

  .portal-filter-form .row,
  .portal-filter-panel .row,
  .portal-filter-bar {
    grid-template-columns: minmax(0, 1fr);
  }

  .portal-pager {
    width: 100%;
    justify-content: space-between;
  }
}
