/* M³GIM Bestand Tab Styles */

/* Sidebar shell (Bestand and Chronik)
   Both views hang on the one left filter column (view-shell). The grid puts the
   column left, the work area scrolls for itself, and an open Konvolut head
   sticks to the top (Projektleitung, 2026-09-03). */

#tab-bestand.tab-content.active,
#tab-chronik.tab-content.active {
  overflow: hidden;
}

.archiv-main {
  overflow-y: auto;
  /* No top padding: the sticky Konvolut head must sit flush on the scroll edge.
     Inline padding plus the cell padding equals the tab padding, so the column
     head text lines up with the active tab's icon above it; the right edge
     takes the band's padding so the table does not touch the scrollbar. */
  padding: 0 var(--space-6) calc(var(--space-3) + var(--record-scroll-space, 0px)) var(--space-1);
  /* Die Arbeitsflaeche ist weiss; den Grauton traegt allein die Sidebar
     (design.md Regel 2). */
  background: var(--surface);
}

/* Strip and column head are one band, but the strip needs air below the brand
   band; sitting flush under it the chips read as part of the navigation
   (Projektleitung, 2026-09-04). It is not sticky, so --table-head-height and
   the sticky offsets of thead and open Konvolut head are untouched. The strip
   keeps its height while empty, so the column head does not jump up against
   the band when the last chip goes. */
.archiv-main .filter-strip {
  padding-inline: var(--space-3);
  padding-block: var(--space-4) var(--space-3);
  min-block-size: 52px;
}
.archiv-main .filter-strip:empty { display: flex; }

/* Table */
.archiv-outside-record { border: 1px solid var(--line-strong); margin: var(--space-3); padding: var(--space-3); }
.archiv-outside-record__head { display: flex; flex-wrap: wrap; justify-content: space-between;
  gap: var(--space-2); padding-bottom: var(--space-3); font-size: var(--text-xs); }
.archiv-outside-record__head button { color: var(--accent); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--border-radius); padding: var(--space-1) var(--space-2); cursor: pointer; }

.archiv-table {
  --bestand-detail-inset: var(--space-3);
  width: 100%;
  border-collapse: collapse;
  /* Fixed layout keeps the expanded detail row (colspan over all columns)
     from widening the table past its container; the detail wraps instead. */
  table-layout: fixed;
}

/* A hairline per row: at this row height padding alone stopped holding the
   lines apart (design rule 11 admits the line where the eye needs it). Hover
   and selection take the tinted step, the row itself stays white. */
.archiv-table td {
  padding: var(--space-2) var(--space-3);
  vertical-align: top;
  border-bottom: 1px solid var(--line-soft);
}

.archiv-table tbody tr {
  cursor: pointer;
  transition: background var(--transition-fast);
}

.archiv-table tbody tr:hover {
  background: var(--surface-2);
}

.archiv-table tbody tr.selected {
  background: var(--accent-soft);
}

/* A Konvolut head is a container: white like every row, set apart by weight, a
   top rule and the chevron before the Signatur. Closed by default; the open
   head sticks below the column head, where it needs an opaque ground of its own
   so the Folio rows scroll under it. */
/* A head is a group boundary and gets a step more air than a Folio row
   (Projektleitung, 2026-09-04). */
.archiv-row--konvolut {
  font-weight: var(--weight-semibold);
}

.archiv-row--konvolut-open {
  position: sticky;
  /* One pixel under the thead so the two sticky layers overlap instead of
     abutting; an abutting edge reads as a slit (Projektleitung, 2026-09-04). */
  inset-block-start: calc(var(--table-head-height) - 1px);
  z-index: var(--z-sticky-header);
  background: var(--surface-2);
}

/* Thead and parked open head form one band: the head carries the bottom line,
   the thead drops its own while a head is open, and the head has no top line. */
.archiv-row--konvolut.archiv-row--konvolut-open td {
  border-top: 0;
  box-shadow: inset 0 -1px 0 var(--border-color);
}

.archiv-table:has(.archiv-row--konvolut-open) thead th {
  box-shadow: none;
}

/* The head is a label row (E-203): it sticks above the Konvolut head and
   stays quiet. */
.archiv-table thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky-header-front);
  block-size: var(--table-head-height);
  padding: 0 var(--space-3);
  text-align: start;
  font-size: var(--text-xs);
  font-weight: var(--weight-normal);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  background: var(--surface-2);
  /* inset shadow instead of a border: under border-collapse a border on a
     sticky cell stays behind while the cell scrolls. */
  box-shadow: inset 0 -1px 0 var(--border-color);
}

.archiv-chevron {
  display: inline-block;
  width: 1em;
  color: var(--color-text-secondary);
  transition: transform var(--transition-fast);
}

.archiv-chevron--open {
  transform: rotate(90deg);
}

/* The chevron of an object row: subordinate to the head's, so it indents by one
   chevron width and stays a step quieter (E-217). */
.archiv-chevron--child {
  margin-inline-start: 1em;
  font-size: 0.9em;
  color: var(--color-text-tertiary);
}

.archiv-row--konvolut td {
  padding-block: var(--space-3);
  border-top: 1px solid var(--border-color);
}

.archiv-row--konvolut td:first-child {
  position: relative;
  padding-inline-start: var(--space-3);
}

.archiv-row--child td:first-child {
  padding-inline-start: var(--space-8);
}

/* F-10: Child rows — hierarchy via indentation only, no background */
.archiv-row--child {
  font-size: var(--text-sm);
}

/* Active / expanded row. Carries the table prefix so it matches the hover rule
   above in specificity and, standing later, wins over it without !important. */
.archiv-table tbody tr.archiv-row--active {
  background: var(--accent-soft);
}

.archiv-row--active td:first-child {
  position: relative;
}

.archiv-row--active td:first-child::before {
  content: '';
  position: absolute;
  inset-block: 0;
  inset-inline-start: var(--bestand-detail-inset);
  inline-size: 3px;
  background: var(--accent);
}

/* Row and detail row are one bracket, so the accent bar of the row and the one
   of .inline-detail have to meet: the collapsed hairline between the two rows
   would cut through them (Projektleitung, 2026-09-05). */
.archiv-row--active td {
  border-bottom: 0;
}

/* Detail expansion row */
.archiv-row--detail {
  cursor: default;
}

.archiv-row--detail:hover {
  background: transparent;
}

/* The bar is the whole mark; an accent line under the detail would be a second
   one for the same state. The row keeps the table hairline. */
.archiv-row--detail td {
  padding: 0;
}

.archiv-row--detail .inline-detail {
  margin-inline-start: var(--bestand-detail-inset);
}

/* Column Widths */
.archiv-col-signatur { width: 160px; }
.archiv-col-titel { width: auto; }
.archiv-col-typ { width: 140px; text-align: start; }
/* A dated span ("25. Dezember 1953 – 12. Jänner 1954") is wider than the column
   and ran under the Entitaeten icons; it breaks into a second line instead of
   being truncated, because a cut date names a year the document does not have. */
.archiv-col-datum { width: 160px; }
.archiv-col-links { width: 140px; text-align: center; }  /* four family icons plus their counts */
.archiv-col-korb { width: 36px; text-align: center; }

.archiv-signatur {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--accent);
}

/* Page count of a Folio row, set beside the title. It states the material and
   not a supplemented value, so it carries no derivation mark; the detail pages
   through what it counts. */
.archiv-pages {
  margin-inline-start: var(--space-2);
  white-space: nowrap;
  vertical-align: baseline;
}

.archiv-titel {
  /* inline-block so overflow/ellipsis apply; an inline span would spill
     into the neighbouring column under table-layout: fixed */
  display: inline-block;
  max-width: 100%;
  vertical-align: bottom;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
  user-select: text;
}

.archiv-row--active .archiv-titel,
.archiv-row--konvolut-open .archiv-titel {
  white-space: normal;
  overflow-wrap: anywhere;
  font-weight: var(--weight-semibold);
}

/* Stand-in for an inherited collective title. The title cell carries no icons
   (E-217), so the bare name stands there, without dash and without italic
   (Projektleitung, 2026-09-03). */
.archiv-folio-hint {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  /* inline-flex swallows the whitespace of the text flow, so the gap to the
     title has to be stated. */
  margin-inline-start: var(--space-1);
  font-size: var(--text-sm);
}

.archiv-folio-hint--konvolut {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
}

/* Title cell of the Konvolut head: title and type distribution stand side by
   side and wrap as a group once the title fills the line. */
.archiv-titel-zeile {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
}

.archiv-titel-zeile .archiv-titel {
  flex: 0 1 auto;
  max-inline-size: 100%;
}

/* Type distribution of the collapsed head, and the page count of a Folio row:
   the same quiet pill, because both count what the row stands for. */
.archiv-konvolut-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  white-space: normal;
  line-height: 1.4;
}

.archiv-konvolut-meta .chip--compact,
.archiv-pages {
  display: inline-flex;
  align-items: center;
  padding: 1px var(--space-1-5);
  font-size: 11px;
  font-family: var(--font-ui);
  font-weight: var(--weight-normal);
  line-height: 1.4;
  background: var(--surface-3);
  color: var(--color-text-secondary);
  border: none;
  border-radius: 3px;
}

.archiv-datum {
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* Consistent absence pattern */
.archiv-datum--undated {
  font-style: italic;
  color: var(--color-absent);
}

/* E-158: typed Erschliessungsanzeige, one family icon per content family with
   its count, the full breakdown in the tooltip. Konvolut aggregates live in the
   head tooltip instead of repeating the icons. The icons are the ones the
   Indizes grid heads carry (Projektleitung, 2026-09-04). */
.archiv-ersch {
  display: inline-flex;
  /* Pairs need a firm gap, or the four counts read as one digit string. */
  gap: var(--space-2);
  align-items: center;
  justify-content: center;
}

.ersch-fam {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  /* absent family: a quiet outline in the muted warm line tone, so the filled
     icons carry the reading weight. */
  color: var(--line-strong);
}

.ersch-fam__icon {
  flex: 0 0 auto;
  stroke-width: 1.25;
}

.ersch-fam--on .ersch-fam__icon { stroke-width: 2; }

.ersch-fam--on.ersch-fam--person      { color: var(--chip-c-person-text); }
.ersch-fam--on.ersch-fam--institution { color: var(--chip-c-institution-text); }
.ersch-fam--on.ersch-fam--ort         { color: var(--chip-c-ort-text); }
.ersch-fam--on.ersch-fam--werk        { color: var(--chip-c-werk-text); }

/* Legend of the open, sticky head: the same four symbols the rows below carry,
   quiet and without numbers, so the column says what it holds (Projektleitung,
   2026-09-04). It reuses the row icon size, so the head keeps its height. */
.archiv-ersch--legend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-tertiary);
}
.archiv-ersch--legend .ersch-fam__icon { stroke-width: 1.5; }

/* The number stays in secondary text colour: the icon already carries the
   family colour, and a coloured digit at this size reads as noise. */
.ersch-fam__count {
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--color-text-secondary);
}

/* The type of an object row is text; the outline badge is left to the
   standalone Konvolut and the unresolved child. */
.badge--plain {
  padding: 0;
  background: transparent;
  color: var(--color-text-primary);
  font-weight: var(--weight-normal);
  font-size: var(--text-sm);
}

.badge--unclassified {
  color: var(--color-absent);
  font-style: italic;
}

/* Konvolut head and object row are keyboard waypoints. The outline sits inside
   the row, because a row outline under border-collapse is cut off by its
   neighbours. */
.archiv-row--konvolut:focus-visible,
#bestand-tbody tr[data-record-row]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Umbruch — same container as the shell (sidebar.css) */

/* Under 700px the six columns no longer fit a readable line. Typ goes first: it
   is the one column a facet already answers (design.md, Bestand). The
   Erschliessungsanzeige keeps its four symbols and drops the counts, which the
   row tooltip still carries, and Datum falls back to the bare year width
   (Projektleitung, 2026-09-04). */
@container view-shell (width < 700px) {
  .archiv-col-typ {
    display: none;
  }

  .archiv-col-datum {
    width: 92px;
  }

  .archiv-col-links {
    width: 96px;
  }

  .ersch-fam__count {
    display: none;
  }

  .archiv-ersch {
    gap: var(--space-1-5);
  }

  .archiv-table td {
    padding-inline: var(--space-2);
  }

  .archiv-table {
    --bestand-detail-inset: var(--space-2);
  }

  .archiv-table thead th {
    padding-inline: var(--space-2);
  }

  .archiv-row--child td:first-child {
    padding-inline-start: var(--space-5);
  }
}

@container view-shell (width < 500px) {
  .archiv-col-signatur {
    width: 88px;
  }

  /* Reserve title space; the full date remains in the opened record. */
  .archiv-col-datum {
    display: none;
  }

  .archiv-col-links {
    width: 76px;
  }

  .archiv-col-korb {
    width: 28px;
  }
}

/* Print — the table alone */

/* On paper the filter column, the strip and the Korb column are all ways of
   getting somewhere; the sheet is the destination. Opening
   every Konvolut is not a CSS matter: applyCollapse() drops the closed
   children before render, so the view has to do it (Projektleitung,
   2026-09-04). */
@media print {
  .view-sidebar,
  .view-shell__sidebar-toggle,
  .filter-strip,
  .archiv-col-korb {
    display: none;
  }

  .view-shell {
    display: block;
    height: auto;
    min-height: 0;
  }

  .archiv-main {
    overflow: visible;
    padding: 0;
  }

  /* A sticky head repeats itself over every page break in print; the table head
     is enough. */
  .archiv-row--konvolut-open {
    position: static;
    background: var(--surface);
  }

  .archiv-table thead th {
    position: static;
    background: var(--surface);
  }

  .archiv-row--konvolut {
    break-after: avoid;
  }

  .archiv-table tbody tr {
    break-inside: avoid;
  }
}
