/* --- layout ------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: calc(100vh - var(--topbar)); }
.sidebar { position: sticky; top: var(--topbar); align-self: start; height: calc(100vh - var(--topbar)); overflow-y: auto;
  padding: var(--s5) var(--s4); display: flex; flex-direction: column; gap: var(--s4); border-right: 1px solid var(--line); background: var(--panel); }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: calc(-1 * var(--s2)); }
.sidebar-head b { font-size: 14px; }
/* collapsed on desktop: a narrow rail with the title written vertically; a click anywhere opens it again */
@media (min-width: 901px) {
  .layout.filters-collapsed { --sidebar: 48px; }
  .filters-collapsed .sidebar { padding: var(--s3) var(--s1); cursor: pointer; }
  .filters-collapsed .sidebar > :not(.sidebar-head) { display: none; }
  .filters-collapsed .sidebar-head { flex-direction: column-reverse; justify-content: flex-end; gap: var(--s3); margin: 0; }
  .filters-collapsed .sidebar-head b { writing-mode: vertical-rl; transform: rotate(180deg); color: var(--muted); white-space: nowrap; }
}
.main { padding: var(--s5); min-width: 0; }

/* --- filter fields ------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .checks legend, .advanced label:not(.inline) { font-size: 12px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=search], select {
  width: 100%; height: 38px; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel); }
input[type=text]:focus, input[type=search]:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; cursor: pointer; }
.checks { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--s1); }
.checks legend { margin-bottom: var(--s1); }
.checks label, label.inline { display: flex; align-items: center; gap: var(--s2); min-height: 32px; cursor: pointer; }
.advanced summary, .pkd-box summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: var(--s2) 0; list-style: none; display: flex; gap: var(--s2); align-items: center; }
.advanced summary::before, .pkd-box summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.advanced[open] summary::before, .pkd-box[open] summary::before { transform: rotate(90deg); }
.advanced summary::-webkit-details-marker, .pkd-box summary::-webkit-details-marker { display: none; }
.advanced[open] { display: flex; flex-direction: column; gap: var(--s2); }
.years { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.years legend { grid-column: 1 / -1; padding: 0; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.years input { width: 100%; height: 38px; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel); }
#clearFilters { align-self: flex-start; margin-top: var(--s2); }

/* wholesaler type combobox */
.combo { position: relative; }
.combo input { padding-right: 36px; }
.combo-clear { position: absolute; right: 4px; top: 4px; width: 30px; height: 30px; border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: var(--r-sm); }
.combo-clear:hover { background: var(--sunken); }
.combo-list { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); max-height: 360px; overflow-y: auto; margin: 0; padding: var(--s1) 0;
  list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-3); }
.combo-list .grp { padding: var(--s2) var(--s3) var(--s1); font-size: 12px; font-weight: 600; color: var(--muted); }
.combo-list [role=option] { padding: 6px var(--s3); cursor: pointer; display: flex; justify-content: space-between; gap: var(--s2); }
.combo-list [role=option] code { color: var(--faint); font-size: 12px; font-family: var(--mono); white-space: nowrap; }
.combo-list [role=option][aria-selected=true], .combo-list [role=option]:hover { background: var(--accent-soft); }
.combo-list mark { background: none; color: var(--accent); font-weight: 600; }
.combo-list .none { padding: var(--s2) var(--s3); color: var(--muted); }
.combo-list .grp.recent { color: var(--accent); }

/* PKD codes */
.pkd-box { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0 var(--s3); background: var(--stripe); }
.pkd-box[open] { padding-bottom: var(--s2); }
.pkd-actions { display: flex; gap: var(--s4); font-size: 12px; margin-bottom: var(--s2); }
.facet { display: grid; grid-template-columns: 18px 1fr auto; gap: var(--s2); align-items: start; padding: 6px 0; cursor: pointer; border-top: 1px solid var(--line); }
.facet input { margin-top: 2px; }
.facet code { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.facet .name { font-size: 14px; line-height: 1.35; }
.facet .src { display: block; font-size: 12px; color: var(--muted); }
.facet .n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 12px; line-height: 18px; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; font-weight: 500; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
