/* Hallmark · results grid: the spreadsheet-style pigeon table
 * Depends on the tokens in style.css; loaded alongside it, never on its own.
 */
/* ── Search toolbar ── */
.toolbar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  align-items: center;
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.search-field { position: relative; flex: 1; min-width: 0; }
.search-field-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-ink-3);
  pointer-events: none;
}
.search-field input {
  height: 40px;
  padding-left: calc(var(--space-3) * 2 + 16px);
}
.search-field input::-webkit-search-cancel-button { cursor: pointer; }
.toolbar-submit { height: 40px; }


/* ── Results table ──
 * The scroll container is capped so the header row and the ring column can
 * stay pinned while the rest of the grid moves under them — the one thing a
 * spreadsheet does that plain HTML tables do not.
 */
.table-wrap {
  overflow: auto;
  max-height: min(70dvh, 46rem);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  /* Stops a sideways swipe over the grid from triggering back-navigation. */
  overscroll-behavior-x: contain;
}
.table-wrap:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

/* Tighter rows than the default table: this grid is for scanning many
   records at once, so vertical padding buys nothing that density doesn't. */
.data-table th, .data-table td { padding: var(--space-2) var(--space-3); }
.data-table th { position: sticky; top: 0; z-index: 2; }
.data-table .cell-ring,
.data-table .col-ring {
  position: sticky;
  left: 0;
  /* Hairline that travels with the frozen column, drawn as a shadow so it
     costs no layout width. */
  box-shadow: 1px 0 0 var(--color-border);
}
.data-table .cell-ring { z-index: 1; }
.data-table .col-ring { z-index: 3; }
.data-table tbody tr:hover .cell-ring { background: var(--color-paper-2); }
/* The link fills its cell rather than hugging the text, so the whole ring
   column is tappable and clears the 24px minimum target size. */
.data-table .cell-ring a {
  display: block;
  margin: calc(var(--space-2) * -1) calc(var(--space-3) * -1);
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table td { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .cell-birth_year { font-variant-numeric: tabular-nums; }
.data-table .cell-actions { text-align: right; white-space: nowrap; }
.data-table .cell-actions .btn + .btn { margin-left: var(--space-1); }
.data-table .col-actions { width: 1%; }

/* Sortable header: the whole label is the control, the arrow slot is always
   reserved so switching columns never reflows the header row. */
.th-content {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: inherit;
  border-radius: var(--radius-sm);
  padding: var(--space-1) 0;
}
.th-sort:hover { color: var(--color-ink); }
.th-arrow {
  display: inline-block;
  width: 0.85em;
  color: var(--color-accent);
  font-weight: 700;
}
th[aria-sort="ascending"] .th-label,
th[aria-sort="descending"] .th-label { color: var(--color-ink); }

/* ── Filter chips ── */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.filter-chips-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  font-size: var(--text-xs);
  color: var(--color-ink);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.chip:hover {
  background: var(--color-paper-2);
  border-color: var(--color-ink-3);
  color: var(--color-ink);
}
.chip .icon { color: var(--color-ink-3); }
.chip:hover .icon { color: var(--color-error); }
.chip-key { color: var(--color-ink-3); }
.chip-value { font-weight: 600; }
.chip-clear-all { color: var(--color-accent); border-style: dashed; }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-ink-3);
  text-align: center;
}
.empty-state-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-paper-2);
  color: var(--color-ink-3);
}
.empty-state p { font-size: var(--text-base); }


/* ── Column filters (spreadsheet-style) ──
 * The popup is a native popover, so it renders in the top layer and escapes
 * the table's scroll container instead of being clipped by it. JS anchors it
 * under its button; the width below is what that maths assumes.
 */
.col-filter {
  position: relative;
  display: inline-flex;
}
.col-filter-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-ink-4);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
/* Pads the hit area out to the 44px finger target without growing the glyph
   or disturbing the header's rhythm. */
.col-filter-btn::before {
  content: '';
  position: absolute;
  inset: calc((22px - var(--tap-target)) / 2);
}
.col-filter-btn:hover {
  background: var(--color-paper-3);
  color: var(--color-ink-2);
}
.col-filter-btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 1px; }
.col-filter-active {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}
.col-filter-active:hover {
  color: var(--color-accent-hover);
  background: var(--color-accent-subtle);
}

.col-filter-popup {
  /* Undo the UA's centred, bordered default for [popover]. */
  position: fixed;
  inset: auto;
  margin: 0;
  border: 1px solid var(--color-border-strong);
  padding: 0;
  width: 248px;
  max-width: calc(100vw - 24px);
  background: var(--color-surface);
  color: var(--color-ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.col-filter-popup:popover-open {
  display: flex;
  flex-direction: column;
}
.col-filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-ink-2);
  border-bottom: 1px solid var(--color-border);
  text-transform: none;
  letter-spacing: 0;
}
.col-filter-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--tap-target);
  height: var(--tap-target);
  margin: calc(var(--space-2) * -1);
  border: none;
  background: transparent;
  color: var(--color-ink-3);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.col-filter-close:hover { background: var(--color-paper-2); color: var(--color-ink); }
.col-filter-search { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border); }
.col-filter-search input { height: 32px; font-size: var(--text-sm); }
.col-filter-list {
  overflow-y: auto;
  max-height: calc(var(--popup-max-h, 320px) - 100px);
  min-height: 80px;
  padding: var(--space-1) 0;
  overscroll-behavior: contain;
}
.col-filter-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-ink);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  transition: background var(--dur-fast) var(--ease-out);
}
.col-filter-option:hover { background: var(--color-paper-2); }
.col-filter-option:focus-within { background: var(--color-accent-subtle); }
.col-filter-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.col-filter-option span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-filter-actions {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border);
  gap: var(--space-2);
  background: var(--color-paper);
}


/* ── Responsive ── */
@media (max-width: 768px) {
  .toolbar { padding: var(--space-2); }
  /* Row actions shed their labels; the icon plus its aria-label carries them. */
  .data-table .cell-actions .btn-label,
  .toolbar-submit .btn-label { display: none; }
  .toolbar-submit { width: var(--tap-target); padding: 0; }
  .chip { min-height: 36px; }
  .col-filter-option { min-height: var(--tap-target); }
}

@media (max-width: 560px) {
  /* Below this the anchored dropdown is wider than the space beside its
     column, so the filter becomes a bottom sheet. The !important rules
     override the inline positioning the JS wrote for the anchored case. */
  .col-filter-popup {
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    width: auto;
    max-width: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .col-filter-popup::backdrop { background: var(--color-scrim); }
  .col-filter-list { max-height: 45dvh; }
  .col-filter-close { display: inline-flex; }
  .col-filter-header { font-size: var(--text-base); padding: var(--space-3); }
  .col-filter-actions { padding: var(--space-3); }
  .col-filter-actions .btn { flex: 1; min-height: var(--tap-target); font-size: var(--text-sm); }
}

@media (max-width: 480px) {
  .data-table td { max-width: 14ch; }
}
