/*
 * Document matrix (persons/documents.blade.php).
 *
 * A person can hold documents against many enrollments, so the link matrix grows
 * one column per enrollment and quickly outgrows the boxed content area. The
 * matrix columns scroll horizontally inside the block; the identity columns
 * (name, employee, details, description) and the row actions stay frozen so a
 * row is still readable once the matrix is scrolled.
 */

.doc-matrix {
  /* The scroll container clips the row action dropdown, so reserve room for it
     to open into. The matching negative margin keeps that room invisible. */
  padding-bottom: 140px;
  margin-bottom: -140px;
}

.doc-matrix > table {
  /* Column widths come from the colgroup, which is what makes the number of
     visible matrix columns predictable. Fixed layout also keeps rendering cheap
     on people holding several hundred documents. */
  table-layout: fixed;
  /* Sticky cells need separated borders to carry their own background. */
  border-collapse: separate;
  border-spacing: 0;
}

.doc-matrix .doc-matrix__frozen,
.doc-matrix .doc-matrix__frozen-right {
  position: sticky;
  z-index: 2;
  background-color: #fff;
}

.doc-matrix .doc-matrix__frozen-right {
  right: 0;
}

.doc-matrix thead .doc-matrix__frozen,
.doc-matrix thead .doc-matrix__frozen-right {
  z-index: 3;
  background-color: #343a40;
}

/* Edge shadows signal that there is more table on the other side. */
.doc-matrix .doc-matrix__frozen--edge {
  box-shadow: 4px 0 6px -3px rgba(0, 0, 0, .28);
}

.doc-matrix .doc-matrix__frozen-right {
  box-shadow: -4px 0 6px -3px rgba(0, 0, 0, .28);
}

/* Fixed layout will not shrink a long word for us. */
.doc-matrix th,
.doc-matrix td {
  overflow-wrap: break-word;
}

/*
 * Print has no viewport to scroll, so flatten the table back out and let every
 * column through. `.print-mode-on` covers layouts/print.blade.php, which renders
 * the print styling on screen rather than through a print media query.
 */
@media print {
  .doc-matrix {
    overflow: visible;
    padding-bottom: 0;
    margin-bottom: 0;
  }

  .doc-matrix > table {
    table-layout: auto;
    min-width: 0 !important;
  }

  .doc-matrix col {
    width: auto !important;
  }

  .doc-matrix .doc-matrix__frozen,
  .doc-matrix .doc-matrix__frozen-right {
    position: static;
    box-shadow: none;
    background-color: transparent;
  }
}

.print-mode-on .doc-matrix {
  overflow: visible;
  padding-bottom: 0;
  margin-bottom: 0;
}

.print-mode-on .doc-matrix > table {
  table-layout: auto;
  min-width: 0 !important;
}

.print-mode-on .doc-matrix col {
  width: auto !important;
}

.print-mode-on .doc-matrix .doc-matrix__frozen,
.print-mode-on .doc-matrix .doc-matrix__frozen-right {
  position: static;
  box-shadow: none;
  background-color: transparent;
}
