/* Shared components (macros in app/templates/_macros.html). Tokens only: no raw colors.
   Narrow-screen rules are at the bottom (max-width: 640px). */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn-sm { min-height: var(--control-sm); padding: 0 var(--space-3); font-size: var(--text-xs); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-fg); }

.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--text); }

.btn-danger { background: var(--bad-bg); border-color: var(--bad-fg); color: var(--bad-fg); }
.btn-danger:hover { background: var(--bad-fg); border-color: var(--bad-fg); color: var(--bad-bg); }

/* A quiet destructive action in a row of ghost buttons ("Remove"). */
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--bad-fg); }
.btn-danger-ghost:hover { background: var(--bad-bg); border-color: transparent; color: var(--bad-fg); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost:disabled, .btn-ghost:disabled:hover { background: transparent; }

/* Full width of its container (auth forms, phone action rows). */
.btn-block { display: flex; width: 100%; }

.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* Form fields */
.field input:not([type="checkbox"], [type="radio"]), .field select, .field textarea {
  width: 100%;
  border-radius: var(--radius);
}
.field-wide { max-width: none; }
.field-required { color: var(--bad-fg); }
.field-hint { color: var(--text-muted); font-size: var(--text-xs); margin: 0; }
.field-error { font-size: var(--text-xs); }

/* Checkbox field: the box sits left of its label text. */
.field-check label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-weight: var(--weight-regular);
  cursor: pointer;
}
.field-check input[type="checkbox"] { flex: 0 0 auto; width: 18px; height: 18px; margin: 3px 0 0; }
.field-check .field-hint, .field-check .field-error { padding-left: calc(18px + var(--space-3)); }

/* Short fields side by side, one column when narrow. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0 var(--space-4);
}
.form-grid .field { max-width: none; min-width: 0; }

/* Read-only value to copy (one-time links). */
.copy-input { width: 100%; font-size: var(--text-sm); background: var(--surface-2); }
.copy-input:focus { background: var(--surface); }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.card > :last-child { margin-bottom: 0; }
.card-title { margin: 0 0 var(--space-3); font-size: var(--text-lg); }
/* A title with something beside it (card's `aside`: a badge, a short note). */
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-4);
}
.card-head .card-title { margin: 0; }
.card-danger { border-color: var(--bad-fg); }
.card-danger .card-title { color: var(--bad-fg); }
.card-danger p { color: var(--text-muted); font-size: var(--text-sm); }
.card-danger .flash { color: var(--bad-fg); }
.card-danger .field { max-width: 34rem; }
.card-danger .field label { overflow-wrap: anywhere; }

/* Section heading between cards or lists on a page; holds a count pill if there is one. */
.section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-8) 0 var(--space-3);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

/* Small heading inside a card or form ("Your titles", a fieldset's legend). */
.subsection-title { margin: 0 0 var(--space-2); padding: 0; font-size: var(--text-base); font-weight: var(--weight-semibold); }

/* Muted helper text under a heading or in place of an empty list; `hint-flush` drops its margin. */
.hint { margin: 0 0 var(--space-3); color: var(--text-muted); font-size: var(--text-sm); }
.hint-flush { margin: 0; }

/* Disclosure: a <details> summary with a chevron that turns when open; `disclosure-sm` is the
   smaller one inside a button. */
.disclosure { list-style: none; cursor: pointer; }
.disclosure::-webkit-details-marker { display: none; }
.disclosure::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}
details[open] > .disclosure::after { transform: translateY(2px) rotate(-135deg); }
.disclosure-sm::after { width: 6px; height: 6px; }
details[open] > .disclosure-sm::after { transform: translateY(1px) rotate(-135deg); }

/* Pickers (setup/_titles.html, _where.html, _keyword_sources.html): the pieces setup's steps
   and the profile's cards share. */
.picker-section { margin: var(--space-6) 0 0; }
/* setup/_keyword_sources.html: the paste box, then the suggestion chips, each the full width. */
.keyword-sources { display: flex; flex-direction: column; gap: var(--space-6); margin: 0 0 var(--space-6); }
.keyword-sources > * { min-width: 0; margin: 0; }

/* Show more (show_more): the hidden items under a "Show N more" toggle. Open, the items come
   first and "Show fewer" moves below them (where a browser can't lay out a <details> as flex,
   it stays above them). */
.show-more { margin-top: var(--space-2); }
.show-more[open] { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.show-more[open] > .show-more-toggle { order: 1; }
.show-more-toggle { padding-inline: var(--space-2); }
.show-more[open] .show-more-closed, .show-more:not([open]) .show-more-opened { display: none; }
.show-more:not([open]) .show-more-body { margin-top: var(--space-2); }

/* Callout: the one accent-tinted block to notice on a page. */
.callout {
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin: 0 0 var(--space-4);
}
.callout > :last-child { margin-bottom: 0; }
.callout a:not(.btn) { color: var(--accent-soft-fg); }

/* Badges and status pills */
.badge, .pill {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  white-space: nowrap;
}
.badge { border-radius: var(--radius-sm); padding: 2px var(--space-2); }
.pill { border-radius: var(--radius-full); padding: 2px var(--space-3); }
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: var(--space-2);
}

.badge-neutral, .pill-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.badge-good, .pill-good { background: var(--good-bg); color: var(--good-fg); }
.badge-warn, .pill-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-bad, .pill-bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge-accent, .pill-accent { background: var(--accent-soft); color: var(--accent-soft-fg); }

/* Term chips; "Golang → Go" when recognised from pasted text. Long text wraps, never overflows. */
.chip-list { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.term-chip {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1);
  max-width: 100%;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--neutral-bg);
  color: var(--neutral-fg);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  overflow-wrap: anywhere;
}

/* Paste box and its recognised terms (the paste_box macro and terms/_recognized.html). */
/* The label across the top, the box with its button beside it, the hint below (the button goes
   under the box on phones): the field's parts join the form's grid (display: contents). */
.paste-box { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); align-items: start; }
.paste-box .field { display: contents; }
.paste-box label { grid-column: 1 / -1; }
.paste-box textarea { grid-column: 1; }
.paste-box .btn { grid-column: 2; grid-row: 2; }
.paste-box .field-hint, .paste-box .field-error { grid-column: 1 / -1; margin: 0; }
@media (max-width: 640px) {
  .paste-box { grid-template-columns: minmax(0, 1fr); }
  .paste-box .btn { grid-column: 1; grid-row: auto; justify-self: start; }
}
.paste-result:not(:empty) { margin-top: var(--space-3); }
.recognized { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* Keyword suggestions for the chosen titles (terms/_suggestions.html). */
.suggestions .subsection-title { margin-bottom: var(--space-1); }

/* Count pill next to a heading. */
.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--space-6);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: var(--neutral-bg);
  color: var(--neutral-fg);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
}

/* Toggle chips (choice_chip): the checkbox stays focusable but invisible; the label is the pill. */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip-input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.chip:has(.chip-input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.chip:has(.chip-input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
}
.chip:has(.chip-input:checked) .chip-label::before { content: "✓ "; }
.chip-addable .chip-label::before { content: "+ " / ""; }
.chip-count { color: var(--text-muted); font-size: var(--text-xs); }
.chip:has(.chip-input:checked) .chip-count { color: inherit; }

/* Round × button (remove-button): removes one item (removable chips). */
.remove-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-sm);
  height: var(--control-sm);
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: var(--text-lg);
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

/* Removable chips (removable_chip): a chosen item and its remove button (or link). */
.removable-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  max-width: 100%;
  min-height: var(--tap-target);
  padding: 0 var(--space-1) 0 var(--space-3);
  border: 1px solid var(--accent);
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.removable-chip-label { min-width: 0; overflow-wrap: anywhere; }
.removable-chip-remove { flex: none; }
.removable-chip-remove:hover { background: var(--surface); }
.removable-chip-count { margin-left: var(--space-1); font-size: var(--text-xs); font-weight: var(--weight-regular); }

/* Add chips (add_chip): a dashed pill that adds one item when clicked. */
.add-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  max-width: 100%;
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border: 1px dashed var(--text-muted);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.add-chip:hover { border-style: solid; background: var(--surface-2); }

/* Title autocomplete rows (title_option) and place search rows (place_option) */
.title-options, .place-options { list-style: none; margin: 0; padding: var(--space-1) 0; }
.title-option, .place-option {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.title-option:hover, .title-option:focus-visible,
.place-option:hover, .place-option:focus-visible { background: var(--surface-2); }
.title-option strong { font-weight: var(--weight-semibold); }
.title-option-label { min-width: 0; overflow-wrap: anywhere; }
.title-option-canonical, .title-option-count { color: var(--text-muted); }
.title-option-count { flex: none; font-size: var(--text-xs); white-space: nowrap; }
.title-options-empty, .place-options-empty { margin: 0; padding: var(--space-2) var(--space-3); color: var(--text-muted); }
.place-option-name { min-width: 0; overflow-wrap: anywhere; }
.place-option-alias, .place-option-detail { color: var(--text-muted); }
.place-option-detail { flex: none; max-width: 50%; font-size: var(--text-xs); text-align: right; }

/* Title search (title_search_field): the box and its Search button on one row, results under them. */
.title-search-row { display: flex; align-items: flex-end; gap: var(--space-2); }
.title-search-field { flex: 1; min-width: 0; margin-bottom: 0; }
.title-results .title-options, .title-results .title-options-empty {
  margin-top: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Seniority choice (seniority_fieldset): a borderless fieldset of chips and a checkbox. */
.seniority-fieldset { min-width: 0; margin: var(--space-6) 0 0; padding: 0; border: 0; }
.seniority-fieldset .chip-list { margin-bottom: var(--space-3); }
.seniority-fieldset .field { margin-bottom: 0; }

/* Keyword level buttons (level_buttons): the pressed one is the keyword's level. */
.level-button {
  min-height: var(--control-sm);
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--neutral-fg);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  cursor: pointer;
}
.level-button:hover { background: var(--surface-2); color: var(--text); }
.level-button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.level-button.level-rather_not[aria-pressed="true"] { border-color: var(--warn-fg); background: var(--warn-bg); color: var(--warn-fg); }
.level-button.level-avoid[aria-pressed="true"] { border-color: var(--bad-fg); background: var(--bad-bg); color: var(--bad-fg); }

/* Keyword level columns (keyword_columns, keyword_chip; setup step 3, the profile): as many
   columns of chips as fit at 10rem or more (all five across the profile's card, three in setup's
   narrower step), two on phones; each chip opens to its level buttons. */
.kw-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: var(--space-3); }
.kw-column { min-width: 0; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); }
.kw-column-title {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.kw-column-weight { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kw-column-rather_not .kw-column-weight { color: var(--warn-fg); }
.kw-column-avoid .kw-column-weight { color: var(--bad-fg); }
.kw-list { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.kw-chip { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.kw-chip[open] { border-color: var(--accent); }
.kw-chip-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 var(--space-2);
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  list-style: none;
  cursor: pointer;
}
.kw-chip-summary::-webkit-details-marker { display: none; }
.kw-chip-summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }
.kw-chip-name { min-width: 0; overflow-wrap: anywhere; }
.kw-chip-menu { display: grid; gap: var(--space-1); padding: 0 var(--space-2) var(--space-2); }
.kw-chip-menu .level-button, .kw-chip-menu .btn { width: 100%; }
/* Drag and drop (static/js/keyword-drag.js; desktop only, so chips get `draggable`): a keyword
   to another column, or an add chip (`data-add-keyword`) into one. */
.kw-chip[draggable="true"] > .kw-chip-summary, [data-add-keyword][draggable="true"] { cursor: grab; }
.kw-chip-dragging { border-style: dashed; border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-fg); }
.kw-column-drop { border-color: var(--accent); background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -2px; }
@media (prefers-reduced-motion: no-preference) {
  .kw-column { transition: background-color 120ms ease, border-color 120ms ease; }
}
@media (max-width: 640px) {
  .kw-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Place rows (setup/_places.html target_row; setup step 2, the profile): one bordered fieldset
   per place, its four fields in a row, two by two on phones; in order of preference in a
   .place-list. */
.place-list { display: grid; gap: var(--space-3); margin: 0 0 var(--space-3); padding: 0; list-style: none; }
.place-rule { margin: var(--space-6) 0 var(--space-4); font-size: var(--text-sm); }
.place-rule p { margin: 0; }
.place-row {
  min-width: 0;
  margin: 0;
  padding: var(--space-3) var(--space-4) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.place-row-new { border-style: dashed; }
.place-row-legend { padding: 0 var(--space-1); color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--weight-semibold); }
.place-row-fields {
  display: grid;
  grid-template-columns: minmax(0, 8rem) minmax(0, 2fr) minmax(0, 1fr) minmax(0, 6.5rem);
  gap: 0 var(--space-3);
  align-items: start;
}
.place-row-fields .field { min-width: 0; max-width: none; margin-bottom: var(--space-2); }
.place-results .place-options, .place-results .place-options-empty {
  margin-bottom: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.place-row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--space-1); }
.place-row-note { margin-right: auto; font-size: var(--text-sm); }
.place-add { border-style: dashed; }

/* Stat tiles */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}
/* Each tile is a card (stat_tiles puts both classes on it). */
.stat-tile { min-width: 0; margin: 0; padding: var(--space-4); }
.stat-tile dt { color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.stat-tile dd { margin: var(--space-1) 0 0; font-size: var(--text-stat); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
.stat-tile .stat-hint { color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--weight-regular); }

/* Data table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin: 0 0 var(--space-4);
}
.data-table { margin: 0; }
.data-table caption { text-align: left; padding: var(--space-3); font-weight: var(--weight-semibold); }
.data-table th {
  background: var(--surface-2);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.data-table th, .data-table td { padding: var(--space-3) var(--space-4); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table-empty { color: var(--text-muted); text-align: center; }

/* Empty state */
.empty-state {
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-6);
  margin: 0 0 var(--space-4);
}
.empty-state-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); margin: 0 0 var(--space-2); }
.empty-state-text { color: var(--text-muted); margin: 0 auto var(--space-4); max-width: 32rem; }

/* Undo bar (undo_bar): a status line with Undo beside it; the marks' "Dismissed · Undo". */
.undo-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-sm);
}
.undo-bar-text { flex: 1 1 14rem; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.undo-bar-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
main > .undo-bar { margin: 0 0 var(--space-4); }

/* Page header */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  margin: var(--space-4) 0 var(--space-6);
}
.page-header h1 { margin: 0; font-size: var(--text-2xl); font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.page-header-text { min-width: 0; }
.page-header-subtitle { color: var(--text-muted); margin: var(--space-1) 0 0; }
.page-header-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
/* page_header(class_="page-header-center"): the actions centred on the title, on phones too. */
.page-header.page-header-center { align-items: center; }

/* Sub-nav: section tabs under a page header (subnav macro). */
.subnav { margin: 0 0 var(--space-6); }
.subnav-top { margin-bottom: var(--space-2); }
.subnav ul { display: flex; flex-wrap: wrap; gap: var(--space-1); list-style: none; margin: 0; padding: 0 0 var(--space-3); border-bottom: 1px solid var(--border); }
.subnav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
}
.subnav-link:hover { background: var(--surface-2); color: var(--text); }
.subnav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-soft-fg); }
.subnav-link[aria-current="page"] .count-pill { background: var(--surface); color: var(--accent-soft-fg); }

/* Filter bar: a GET form of filters in a card (the job lists' sidebar, leads/_filters.html).
   Phones fold it behind the <details> summary; wider screens hide the summary and always show
   the body (see the media query). */
.filter-bar { padding: var(--space-4) var(--space-5); }
.filter-bar-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  font-weight: var(--weight-semibold);
}
.filter-bar-summary::after { margin-left: auto; }
.filter-bar-details[open] .filter-bar-summary { margin-bottom: var(--space-3); }
.filter-bar-active { color: var(--text-muted); font-weight: var(--weight-regular); }
.filter-bar .field { max-width: none; min-width: 0; }

@media (min-width: 641px) {
  /* Browsers that can style the details content (::details-content) show the fields at all
     times; older ones keep the collapsible summary, which still works. */
  @supports selector(::details-content) {
    .filter-bar-summary { display: none; }
    .filter-bar-details::details-content { content-visibility: visible; block-size: auto; }
  }
}

/* Sort select (sort_select macro). */
.sort-select { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.sort-select label { color: var(--text-muted); font-size: var(--text-sm); white-space: nowrap; }
.sort-select select { width: auto; min-width: 0; border-radius: var(--radius); }

/* Pagination (pagination macro): "Page X of Y" on the left, links on the right. */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0;
}
.pagination-status { margin: 0 auto 0 0; color: var(--text-muted); font-size: var(--text-sm); }
.pagination-pages { display: flex; flex-wrap: wrap; gap: var(--space-1); list-style: none; margin: 0; padding: 0; }
.pagination-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control);
  min-height: var(--control);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
}
.pagination-link:hover { background: var(--surface-2); color: var(--text); }
.pagination-link[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.pagination-link[aria-disabled="true"] { background: transparent; border-color: transparent; color: var(--text-muted); cursor: default; }
.pagination-gap { display: inline-flex; align-items: center; padding: 0 var(--space-1); color: var(--text-muted); }

/* Styleguide page */
.sg-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 0 0 var(--space-4); }

/* Narrow screens */
@media (max-width: 640px) {
  .btn { min-height: var(--tap-target); white-space: normal; text-align: center; }
  .btn-sm { min-height: var(--tap-target); }
  .btn-block-phone { display: flex; width: 100%; }
  .field input:not([type="checkbox"], [type="radio"], [type="file"]), .field select, .copy-input { min-height: var(--tap-target); }
  .field-check label { min-height: var(--tap-target); align-items: center; }
  .field-check input[type="checkbox"] { margin: 0; }
  .subnav-link { min-height: var(--tap-target); }
  .callout { padding: var(--space-4); }

  .filter-bar { padding: var(--space-2) var(--space-4); }
  .sort-select select { min-height: var(--tap-target); }

  .place-row { padding-inline: var(--space-3); }
  .place-row-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .place-field-kind, .place-field-where { grid-column: 1 / -1; }
  .level-button { min-height: var(--control); padding: 0 var(--space-1); font-size: var(--text-xs); white-space: normal; }

  /* Phones: Previous, "Page X of Y", Next on one line; the numbered pages are left out. */
  .pagination { flex-wrap: nowrap; }
  .pagination-pages { display: none; }
  .pagination-link { min-height: var(--tap-target); }
  .pagination-prev { order: 1; }
  .pagination-status { order: 2; flex: 1 1 auto; margin: 0; text-align: center; }
  .pagination-next { order: 3; }

  .stat-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .page-header { align-items: stretch; flex-direction: column; }
  .page-header-actions .btn, .form-actions .btn { flex: 1 1 auto; }

  .table-wrap { background: none; border: 0; border-radius: 0; overflow: visible; }
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: var(--space-2) var(--space-4);
    margin-bottom: var(--space-3);
  }
  .data-table td {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    text-align: right;
    overflow-wrap: anywhere;
  }
  .data-table tbody tr:last-child td { border-bottom: 1px solid var(--border); }
  .data-table tbody tr td:last-child { border-bottom: 0; }
  .data-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    text-align: left;
  }
  .data-table td.data-table-empty { justify-content: center; }
  .data-table td.data-table-empty::before { content: none; }
  /* Plain links in a cell get a 44px tap target. */
  .data-table td a:not(.btn) { display: inline-flex; align-items: center; min-height: var(--tap-target); }
}
