@layer components {
  /* Table Component
     ========================================================================== */

  .table {
    width: 100%;
    border-collapse: collapse;
    border: none;
    margin-block: 0;
    font-size: var(--font-small-medium-responsive);
  }

  /* Remove all default borders */
  .table,
  .table thead,
  .table tbody,
  .table tr,
  .table th,
  .table td {
    border-left: none;
    border-right: none;
  }

  /* Header */
  .table th {
    padding: var(--block-space-half) var(--inline-space);
    text-align: left;
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-small-responsive);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-top: none;
    border-bottom: 1.5px solid var(--color-gray-dark);
  }

  .table th:first-child {
    padding-inline-start: 0;
  }

  .table th:last-child {
    padding-inline-end: 0;
  }

  /* Cells */
  .table td {
    padding: var(--block-space-half) var(--inline-space);
    vertical-align: middle;
    border-top: none;
    border-bottom: var(--border);
  }

  .table td:first-child {
    padding-inline-start: 0;
  }

  .table td:last-child {
    padding-inline-end: 0;
  }

  /* Compact variant — tighter rows for dense lists (e.g. the admin tags table) */
  .table--compact th,
  .table--compact td {
    padding-block: var(--block-space-third);
  }


  /* Active row (current item) */
  .table tbody tr.table-active {
    background-color: var(--color-blue-light);
  }

  .table tbody tr.table-active:hover {
    background-color: var(--color-blue-light);
  }

  /* Alignment helpers */
  .table .text-right,
  .table th.text-right,
  .table td.text-right {
    text-align: right;
  }

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

  /* Action column: a last cell holding controls never wraps; a last cell of prose does */
  .table td:last-child:has(a, button, form, input, select) {
    white-space: nowrap;
  }

  /* Text variant — every column carries prose (e.g. the correction diff): rows align at the top */
  .table--text td {
    vertical-align: top;
  }

  /* Numeric columns - right align */
  .table td[data-type="number"],
  .table th[data-type="number"] {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  /* Remove bottom border on last row */
  .table tbody tr:last-child td {
    border-bottom: none;
  }

  /* The award cut line stands in for the row border above it */
  .table tr:has(+ .award-cut-line) td,
  .table .award-cut-line td {
    border-bottom: none;
  }

  /* Fixed table layout variant */
  .fixed-table {
    table-layout: fixed;
    width: 100%;
  }

  .fixed-table th,
  .fixed-table td {
    width: 33.33%;
  }

  /* Shrink columns to fit content */
  .table .col-shrink {
    width: 1%;
    white-space: nowrap;
  }

  /* Limit column width (for name columns that shouldn't expand too much) */
  .table .col-20 {
    width: 20%;
  }

  /* Diagonal header text for compact columns */
  .table .th-diagonal {
    height: 7em;
    vertical-align: bottom;
    position: relative;
  }

  .table .th-diagonal > span {
    position: absolute;
    bottom: 0.5em;
    left: 50%;
    transform: rotate(-45deg);
    transform-origin: bottom left;
    white-space: nowrap;
  }

  /* Even width for status columns (ERFÜLLT, AUSGEFÜLLT?, QUALIFIKATION) */
  .table .th-status-col {
    width: 5em;
  }

  /* Responsive column hiding - uses container queries when available */
  .overflow-x {
    container-type: inline-size;
  }

  /* Container-based hiding (responds to actual available space) */
  @container (max-width: 1100px) {
    .table .hide-lg {
      display: none;
    }
  }

  @container (max-width: 900px) {
    .table .hide-md {
      display: none;
    }
  }

  @container (max-width: 500px) {
    .table .hide-sm {
      display: none;
    }
  }

  /* Fallback for tables without container (viewport-based) */
  @media (max-width: 1700px) {
    .table:not(.overflow-x .table) .hide-lg {
      display: none;
    }
  }

  @media (max-width: 1200px) {
    .table:not(.overflow-x .table) .hide-md {
      display: none;
    }
  }

  @media (max-width: 640px) {
    .table:not(.overflow-x .table) .hide-sm {
      display: none;
    }
  }
}
