/* People and companies (/contacts; TKT-0830, TKT-0831): two big tables for the desk, with the filters down the side.
   contacts.js is the page, table-view.js draws the table, and the tokens (colors, radii, control heights) are
   site.css's. Three layouts:
     wide (1100 px and up)   the filters beside the table; the table scrolls in its own box, headings and names held
     narrow (641 to 1099)    the filters fold away above the table behind a button; the table scrolls sideways too
     phone (640 and under)   no box: each row is a card in the page, with the name, a line about them, phone and email */

.tab-count { margin-left: 4px; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }

.table-layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); gap: 16px; align-items: start; }
.table-layout > .card + .card { margin-top: 0; }
/* when the page scrolls to the filters or back to the table, they stop below the site's top bar, not under it */
.filter-rail, .table-card { scroll-margin-top: 76px; }

/* ==== THE FILTERS ==== */
.filter-rail { position: sticky; top: 12px; max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px 6px; }
.rail-title { margin: 0 0 6px; font-size: calc(11.5px * var(--text-scale)); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.filter { border-top: 1px solid var(--line-soft); }
.filter summary { display: flex; align-items: center; gap: 8px; min-height: max(36px, var(--control-h-small)); font-weight: 600; cursor: pointer; list-style: none; border-radius: 6px; }
.filter summary::-webkit-details-marker { display: none; }
/* the fold's arrow: down when shut, up when open */
.filter summary::after { content: ""; flex: none; width: 7px; height: 7px; margin: -3px 4px 0 0; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.filter[open] summary::after { margin-top: 3px; transform: rotate(-135deg); }
.filter summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* how many choices are ticked in a fold, so a shut fold still says it is narrowing the table */
.filter-ticked { margin-left: auto; min-width: 20px; padding: 1px 6px; border-radius: var(--radius-pill); background: var(--accent); color: var(--accent-ink);
  font-size: calc(12px * var(--text-scale)); font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.filter-ticked:empty { visibility: hidden; }
.filter-find { margin: 2px 0 6px; min-height: var(--control-h-small); padding: 4px 10px; font-size: calc(14px * var(--text-scale)); }
.filter-find[hidden] { display: none; }
.filter-choices { display: flex; flex-direction: column; padding-bottom: 8px; }
.filter-choices .hint { margin: 2px 0 4px; }
.filter-choices button.link { align-self: flex-start; margin-top: 4px; }
label.filter-choice { display: flex; align-items: center; gap: 8px; margin: 0; min-height: 30px; font-weight: 400; cursor: pointer; border-radius: 6px; }
@media (hover: hover) { label.filter-choice:hover { background: var(--raise); } }
.filter-choice input { flex: none; }
.choice-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice-count { flex: none; color: var(--muted); font-size: calc(13px * var(--text-scale)); font-variant-numeric: tabular-nums; }

/* ==== THE TABLE'S CARD ==== */
.table-card { min-width: 0; padding: 14px 0 8px; }
.table-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 14px; }
#table-search { flex: 1 1 260px; min-width: 0; max-width: 560px; }
#filters-toggle { display: none; }
#show-archived[hidden], #table-more[hidden], .table-status .chips[hidden] { display: none; }
.table-bar-end { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
/* the Columns menu's ticks: one under another, each a whole row to click */
.more-menu-list label.check { margin: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
@media (hover: hover) { .more-menu-list label.check:hover { background: var(--raise); } }
.more-menu-list button.small { margin-top: 4px; }
.table-status { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; min-height: 44px; padding: 8px 14px; }
.count-line { font-weight: 600; font-variant-numeric: tabular-nums; }
.table-status .chips { margin: 0; align-items: center; }
#table-foot { margin: 8px 14px 0; }
#table-foot:empty { display: none; }

/* ==== THE TABLE ====
   Every row is one line high and the same height (--row-h), which is what lets table-view.js draw only the rows in
   view: it measures one row and knows where every other one is. Words too long for a column end in "…". */
.rows-compact { --row-h: 34px; }
.rows-regular { --row-h: 44px; }
.rows-roomy { --row-h: 58px; }
/* a finger needs 44 px, so on a touch screen compact rows are as tall as regular ones */
@media (pointer: coarse) { .rows-compact { --row-h: 44px; } .rows-regular { --row-h: 48px; } }

.table-scroll { overflow: auto; overscroll-behavior: contain; border-top: 1px solid var(--line); }
.table-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
/* separate borders, because a collapsed border does not travel with a heading that is held in place */
.data-table { table-layout: fixed; border-collapse: separate; border-spacing: 0; }
.data-table th, .data-table td { background: var(--surface); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.data-table td { height: var(--row-h); padding: 0 12px; }
.data-table th { position: sticky; top: 0; z-index: 2; padding: 3px 4px; }
/* the name stays in sight while the other columns scroll sideways */
.data-table th:first-child, .data-table td:first-child { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 var(--line-soft); }
.data-table th:first-child { z-index: 3; }
.data-table .num { text-align: right; }
.data-table td a { font-weight: 400; }
@media (hover: hover) { .data-table tr.data-row:hover td { background: var(--raise); } }
.data-table tr.data-row:focus-within td { background: var(--raise); }
/* the rows not drawn, above and below: one empty row of their height (table-view.js) */
.data-table .gap-row td { height: auto; padding: 0; border: 0; }
.data-table td.empty { height: auto; padding: 36px 16px; white-space: normal; text-align: center; }
.data-table .skeleton-row td { padding: 12px; }

/* a heading is a button that sorts by its column; the arrow says which way */
button.sort { --btn-ink: var(--muted); width: 100%; min-height: var(--control-h-small); justify-content: flex-start; gap: 4px; padding: 2px 8px; border: 0; border-radius: 6px; background: none;
  box-shadow: none; font-size: inherit; font-weight: inherit; letter-spacing: inherit; text-transform: inherit; }
/* a number column's heading sits against the right edge, with its arrow on the left of the words: if a narrow
   column runs out of room, it is the arrow that is cut, never the start of the heading */
.num button.sort { flex-direction: row-reverse; justify-content: flex-start; }
th[aria-sort] button.sort { --btn-ink: var(--ink); }
@media (hover: hover) { button.sort:hover { --btn-ink: var(--ink); background: var(--raise); } }
button.sort:active { transform: none; }
.sort-mark { flex: none; width: 8px; font-size: calc(9px * var(--text-scale)); }
.sort-mark:empty { display: none; }   /* a column that is not sorted keeps no room for an arrow */

/* the name cell: the star, then the name (and, in roomy rows and on a phone, a line under it) */
.row-name { display: flex; align-items: center; gap: 2px; min-width: 0; }
.row-name .no-star { flex: none; width: 32px; }
.row-words { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-words .badge { margin-left: 6px; vertical-align: 1px; }
.row-sub { display: none; overflow: hidden; text-overflow: ellipsis; font-size: calc(12px * var(--text-scale)); color: var(--muted); }
.rows-roomy .row-sub { display: block; }

/* "Show 716 people" under the filters, on a narrow screen: shuts them and goes back to the table */
#rail-done { display: none; }

/* ==== NARROW: THE FILTERS FOLD AWAY ABOVE THE TABLE ==== */
@media (max-width: 1099px) {
  .table-layout { grid-template-columns: minmax(0, 1fr); }
  #filters-toggle { display: inline-flex; }
  .filter-rail { display: none; position: static; max-height: none; }
  .rail-open .filter-rail { display: block; }
  #rail-done { display: flex; width: 100%; margin: 10px 0 8px; }
}

/* ==== PHONE: EACH ROW IS A CARD ==== */
@media (max-width: 640px) {
  .table-card { padding: 12px 0 8px; }
  .table-bar-end { display: none; }   /* columns and row height are the table's; a card shows what fits */
  #table-search { flex-basis: 100%; max-width: none; }
  .table-scroll { overflow: visible; }
  .data-table, .data-table tbody { display: block; min-width: 0 !important; }
  .data-table colgroup, .data-table thead { display: none; }
  .data-table tr.data-row { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
  .data-table td { display: none; height: auto; padding: 0; border: 0; white-space: normal; overflow: visible; }
  .data-table td:first-child { position: static; box-shadow: none; }
  .data-table td[data-col="name"] { display: block; }
  /* how to reach them, under the name: tall enough for a thumb */
  .data-table td[data-col="phone"]:not(:empty), .data-table td[data-col="email"]:not(:empty) { display: block; padding-left: 34px; overflow-wrap: anywhere; }
  .data-table td[data-col="phone"] a, .data-table td[data-col="email"] a { display: inline-flex; align-items: center; min-height: 36px; }
  .data-table td.empty { display: block; }
  .data-table tr.data-row:hover td, .data-table tr.data-row:focus-within td { background: var(--surface); }
  .row-name { align-items: flex-start; }
  .row-words { white-space: normal; padding-top: 5px; }
  .row-sub { display: block; white-space: normal; }
  #table-more { display: flex; margin: 12px auto 4px; }
}
