/* The viewer: the selected file as rows, under the folder in the data panel.
   js/table.js builds it. Dense on purpose: this is an inspector a reader
   glances at, not a report, and the panel it lives in is about 420px wide
   until somebody drags it wider.

   Every color here is one of style.css's tokens, so the light theme
   (data-theme="light" on <html>) needs no rules of its own. Link this after
   css/style.css. */

/* The host is #viewer, which style.css already makes a flex item with
   min-height: 0, so it has a height. Turning it into a flex column is what
   gives .tv-rows a definite height to scroll inside, which is in turn what
   makes the sticky header stick to the rows instead of scrolling away with
   them. js/table.js adds this class and removes it again on clear(). */
.tv-host {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ----- the filter and the count ----- */

.tv-bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
}

.tv-filter-row { display: flex; align-items: center; gap: 6px; }

.tv-filter {
  flex: 1;
  min-width: 0;
  font: 12.5px ui-monospace, Consolas, "Cascadia Mono", monospace;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--button-edge);
  border-radius: 4px;
  padding: 4px 7px;
}
.tv-filter:focus { outline: none; border-color: var(--accent); }
/* A filter that is on has to look on: a reader who forgets one is reading a
   row count that is not the file's. */
.tv-filter.on { border-color: var(--busy); color: var(--busy); }

.tv-clear { flex: 0 0 auto; white-space: nowrap; }

.tv-count {
  color: var(--dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.tv-count.on { color: var(--busy); }

/* ----- the notes and the dtype warnings ----- */

/* Capped, so a file with a dozen notes cannot push the rows off the panel,
   and scrollable so none of them is lost. */
.tv-info {
  flex: 0 0 auto;
  max-height: 40%;
  overflow: auto;
  padding: 6px 8px;
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
}
.tv-info:empty { display: none; }

.tv-note { font-size: 12px; margin: 0 0 3px; }
.tv-note:last-child { margin-bottom: 0; }

.tv-warnings {
  margin: 6px 0 0;
  padding: 6px 8px 6px 20px;
  list-style: disc;
  border-left: 2px solid var(--busy);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}
.tv-warnings li { margin: 0 0 2px; }
.tv-warnings li:last-child { margin-bottom: 0; }
.tv-warn-col {
  font-family: ui-monospace, Consolas, "Cascadia Mono", monospace;
  color: var(--busy);
}

/* ----- the rows ----- */

.tv-rows {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: var(--panel-2);
}

.tv-table {
  /* separate, not collapse: a collapsed border on a sticky header is drawn
     by the cell that scrolls away, so the header loses its line under it. */
  border-collapse: separate;
  border-spacing: 0;
  font: 12px/1.35 ui-monospace, Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.tv-table th,
.tv-table td {
  border-bottom: 1px solid var(--row-edge);
  border-right: 1px solid var(--row-edge);
  padding: 3px 6px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--edge);
  font-weight: 600;
}

/* The row numbers stay visible while the columns scroll sideways, which in a
   narrow panel they do constantly. Written with the table in the selector
   because the plain cell rules above would otherwise win on specificity and
   left-align them. */
.tv-table td.tv-num,
.tv-table th.tv-corner {
  position: sticky;
  left: 0;
  background: var(--panel);
  color: var(--dim);
  text-align: right;
  font-size: 11px;
  padding: 3px 6px;
}
.tv-table td.tv-num { z-index: 1; }
.tv-table th.tv-corner { z-index: 3; }

.tv-table tbody tr:hover td { background: var(--select); }

/* numbers right, text left: a column of numbers that does not line up at the
   decimal point cannot be read down */
.tv-table td.tv-num-col { text-align: right; }
.tv-table th.tv-num-col .tv-th { align-items: flex-end; }

.tv-empty {
  color: var(--dim);
  font-style: italic;
  font-size: 11px;
}

/* ----- a header, which is a button ----- */

.tv-th {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  width: 100%;
  background: none;
  border: none;
  border-radius: 0;
  padding: 3px 6px;
  font: inherit;
  color: var(--text);
  text-align: inherit;
  cursor: pointer;
}
.tv-th:hover:not(:disabled) { border: none; color: var(--accent); }
.tv-th:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }

.tv-th-line { display: flex; align-items: center; gap: 3px; min-width: 0; }
/* min-width: 0 so a long column name shrinks and ellipsizes instead of
   pushing the arrow out of the cell */
.tv-th-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.tv-dtype {
  color: var(--dim);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.03em;
}

/* the column pandas will read as something the reader may not expect */
.tv-flag {
  flex: 0 0 auto;
  color: var(--busy);
  font-weight: 700;
  cursor: help;
}

/* A CSS triangle rather than a character, so no font gets a say in whether
   it is a glyph or a picture. The transparent sides are there even when the
   column is not the sorted one, so clicking a heading does not shift every
   heading sideways by 8px. */
.tv-arrow {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}
.tv-arrow.asc { border-bottom: 5px solid var(--accent); }
.tv-arrow.desc { border-top: 5px solid var(--accent); }

/* ----- a file with nothing to show ----- */

.tv-message { padding: 14px 16px 0; }
.tv-message:last-child { padding-bottom: 14px; }

@media (max-width: 768px) {
  /* The data panel is hidden at this width (style.css), so this only matters
     to a page that chooses to show the viewer anyway. */
  .tv-table th, .tv-table td { max-width: 20ch; padding: 3px 5px; }
  .tv-info { max-height: 50%; }
}
