/* Pay-items search — design tokens & layout */

:root {
  /* Reaalprojekt brand palette */
  --brand-navy: #282868;            /* logo blue */
  --brand-navy-deep: #1c1c4c;
  --brand-ink: #1a1320;             /* logo wordmark */

  --bg: oklch(0.985 0.003 275);
  --bg-elev: oklch(1 0 0);
  --ink: oklch(0.20 0.02 280);
  --ink-soft: oklch(0.40 0.025 280);
  --muted: oklch(0.55 0.02 280);
  --faint: oklch(0.78 0.01 280);
  --border: oklch(0.92 0.01 280);
  --border-strong: oklch(0.84 0.015 280);

  /* Accent = brand navy */
  --accent: oklch(0.32 0.135 278);
  --accent-soft: oklch(0.95 0.035 278);
  --accent-soft-2: oklch(0.90 0.06 278);
  --accent-ink: oklch(0.28 0.13 278);
  --accent-hover: oklch(0.38 0.15 278);

  --highlight: oklch(0.92 0.16 95);
  --highlight-ink: oklch(0.35 0.10 70);
  --success: oklch(0.55 0.15 145);
  --danger: oklch(0.55 0.18 25);
  --shadow: 0 1px 2px oklch(0.2 0.05 280 / 0.05), 0 8px 24px oklch(0.2 0.08 280 / 0.07);
  --radius: 8px;
  --radius-lg: 12px;
  --row-h: 56px;

  --font-ui: "Geist", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

:root.theme-dark {
  --bg: oklch(0.16 0.02 278);
  --bg-elev: oklch(0.21 0.025 278);
  --ink: oklch(0.96 0.005 80);
  --ink-soft: oklch(0.82 0.008 80);
  --muted: oklch(0.65 0.01 280);
  --faint: oklch(0.40 0.015 280);
  --border: oklch(0.30 0.025 278);
  --border-strong: oklch(0.40 0.03 278);
  --accent: oklch(0.72 0.14 278);
  --accent-soft: oklch(0.28 0.08 278);
  --accent-soft-2: oklch(0.34 0.10 278);
  --accent-ink: oklch(0.88 0.10 278);
  --accent-hover: oklch(0.78 0.14 278);
  --highlight: oklch(0.55 0.16 95);
  --highlight-ink: oklch(0.96 0.05 95);
  --shadow: 0 1px 2px oklch(0 0 0 / 0.4), 0 12px 32px oklch(0 0 0 / 0.5);
}

:root.density-compact {
  --row-h: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

input {
  font-family: inherit;
  color: inherit;
  font-size: inherit;
}

a { color: var(--accent); text-decoration: none; }

/* ─── Layout ──────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 24px 32px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  white-space: nowrap;
}
.brand-mark {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--accent);
  padding: 4px 8px;
  background: var(--accent-soft);
  border-radius: 6px;
  line-height: 1;
}
.brand-title {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand-sub {
  color: var(--muted);
  font-size: 13px;
}

/* Hide mobile-only chrome by default */
.icon-btn.hamburger,
.sidebar-head-mobile,
.sidebar-backdrop { display: none; }

.brand-logo {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 120ms;
}
.brand-logo:hover { background: var(--accent-soft); }
.brand-logo img {
  height: 28px;
  width: auto;
  display: block;
}
:root.theme-dark .brand-logo {
  background: oklch(0.96 0.005 80);
}
:root.theme-dark .brand-logo:hover { background: white; }

.search {
  flex: 1;
  max-width: 640px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  transition: border-color 120ms, box-shadow 120ms;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.search svg {
  flex: 0 0 18px;
  color: var(--muted);
}
.search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 15px;
}
.search input::placeholder { color: var(--muted); }
.search-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}
.search-clear {
  color: var(--muted);
  padding: 4px;
  border-radius: 4px;
  display: none;
}
.search-clear:hover { background: var(--border); color: var(--ink); }
.search.has-value .search-clear { display: flex; }
.search.has-value .search-hint { display: none; }

.topbar-meta {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.reset-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 100ms;
}
.reset-all-btn:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
}
.reset-all-btn svg { flex: 0 0 13px; }

/* ─── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  grid-column: 1;
  padding: 24px 16px 80px 32px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  height: calc(100vh - 77px);
  position: sticky;
  top: 77px;
}

.side-section {
  margin-bottom: 28px;
}
.side-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cat-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--ink-soft);
  transition: background 100ms, color 100ms;
}
.cat-item:hover { background: var(--border); color: var(--ink); }
.cat-item.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 500;
}
.cat-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  padding: 2px 5px;
  background: var(--border);
  border-radius: 3px;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
}
.cat-item.active .cat-num { background: var(--bg-elev); color: var(--accent); }
.cat-label { flex: 1; line-height: 1.3; }
.cat-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.sub-list {
  list-style: none;
  padding: 4px 0 4px 28px;
  margin: 0;
}
.sub-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--muted);
}
.sub-item:hover { background: var(--border); color: var(--ink); }
.sub-item.active { color: var(--accent-ink); font-weight: 500; }
.sub-num {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  flex: 0 0 26px;
}
.sub-item.active .sub-num { color: var(--accent); }
.sub-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Unit filter chips */
.unit-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 100ms;
}
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.chip-count {
  font-size: 10px;
  opacity: 0.7;
}

/* Pinned list */
.pinned-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.pinned-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.pinned-item:hover { background: var(--border); }
.pinned-item .code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-ink);
  flex: 0 0 auto;
}
.pinned-item .desc {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.pinned-item button {
  opacity: 0;
  color: var(--muted);
  padding: 2px;
}
.pinned-item:hover button { opacity: 1; }
.pinned-item button:hover { color: var(--danger); }

.empty-note {
  font-size: 12px;
  color: var(--muted);
  padding: 0 8px;
  font-style: italic;
}

.reset-btn {
  font-size: 12px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.reset-btn:hover { color: var(--accent); }

/* ─── Main ────────────────────────────────────────────────── */

.main {
  grid-column: 2;
  padding: 16px 32px 80px;
  min-width: 0;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 4px;
  font-size: 12px;
}
.crumb button {
  color: inherit;
  font-size: 14px;
  line-height: 1;
}
.crumb button:hover { color: var(--danger); }
.crumbs-sep { color: var(--faint); }

/* Result list */
.results-head {
  display: grid;
  grid-template-columns: 220px 1fr 80px 110px;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 77px;
  background: var(--bg);
  z-index: 5;
}

.row {
  display: grid;
  grid-template-columns: 220px 1fr 80px 110px;
  gap: 16px;
  align-items: center;
  padding: 0 16px;
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 80ms;
}
.row:hover { background: var(--accent-soft); }
.row.copied { background: oklch(0.94 0.10 145); }
.row.copied:hover { background: oklch(0.92 0.13 145); }

.row .code-cell {
  font-family: var(--font-mono);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.01em;
}
.code-segs { display: inline-flex; }
.code-seg { color: var(--ink); }
.code-pad { color: var(--faint); }
.code-cell mark, .desc-cell mark {
  background: var(--highlight);
  color: var(--highlight-ink);
  border-radius: 2px;
  padding: 0 1px;
}

.desc-cell {
  font-size: 14px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.desc-cell .params {
  color: var(--muted);
  font-size: 13px;
}

.unit-cell {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  text-align: left;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.icon-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--muted);
  transition: all 100ms;
}
.icon-btn:hover { background: var(--border-strong); color: var(--ink); }
.icon-btn.pinned { color: var(--accent); }
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  transition: all 100ms;
  font-variant-numeric: tabular-nums;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.row.copied .copy-btn { border-color: oklch(0.55 0.15 145); color: oklch(0.30 0.15 145); background: oklch(0.95 0.10 145); }

/* Variant grouping */
.row.has-variants .variant-pill {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  padding: 2px 6px;
  background: var(--border);
  border-radius: 999px;
  margin-left: 6px;
}

/* Empty state */
.empty-state {
  padding: 80px 24px;
  text-align: center;
  color: var(--muted);
}
.empty-state h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-weight: 500;
}
.empty-state p { margin: 4px 0; font-size: 13px; }
.empty-state code {
  font-family: var(--font-mono);
  background: var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* Facet panel — dynamic narrow-by */
.facet-panel {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-2);
  border-radius: var(--radius-lg);
}
.facet-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--accent-ink);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.facet-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--accent-soft-2);
}
.facet-groups {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 16px;
  align-items: baseline;
}
.facet-group {
  display: contents;
}
.facet-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-ink);
  padding-top: 4px;
}
.facet-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-bottom: 4px;
}
.facet-opt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 100ms;
  font-variant-numeric: tabular-nums;
}
.facet-opt:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}
.facet-opt.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.facet-opt.active:hover { background: var(--accent-hover); }
.facet-count {
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.facet-opt.active .facet-count { color: oklch(0.95 0.04 278); }
.facet-x {
  font-size: 13px;
  line-height: 1;
  opacity: 0.8;
}
.facet-more {
  display: inline-block;
}
.facet-more summary {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  font-size: 12px;
  color: var(--accent-ink);
  cursor: pointer;
  list-style: none;
}
.facet-more summary::-webkit-details-marker { display: none; }
.facet-more summary:hover { background: var(--bg-elev); }
.facet-more[open] summary { display: none; }
.facet-more[open] .facet-opts {
  display: inline-flex;
  margin-left: 0;
}

/* Recently-used strip */.recent-strip {
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.recent-strip h4 {
  margin: 0 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
}
.recent-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  transition: all 100ms;
  text-align: left;
  width: 100%;
}
.recent-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.recent-card .code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--accent-ink);
}
.recent-card .desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Drawer ──────────────────────────────────────────────── */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0.20 0.01 80 / 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms;
  z-index: 50;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 520px;
  max-width: 95vw;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1;
  line-height: 1.35;
}
.drawer-close {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--muted);
}
.drawer-close:hover { background: var(--border); color: var(--ink); }

.drawer-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.param-group {
  margin-bottom: 20px;
}
.param-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.param-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.param-opt {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 100ms;
}
.param-opt:hover { border-color: var(--accent); color: var(--accent-ink); }
.param-opt.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.param-opt.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.drawer-result {
  padding: 16px;
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.drawer-result.matched { border-color: var(--accent); }
.drawer-result-code {
  font-family: var(--font-mono);
  font-size: 18px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.drawer-result-desc {
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 13.5px;
}
.drawer-result-meta {
  margin-top: 10px;
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
}
.drawer-actions {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.btn-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  transition: filter 100ms;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  background: var(--bg);
  color: var(--ink-soft);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
}
.btn-secondary:hover { color: var(--ink); border-color: var(--ink-soft); }

/* ─── Toast ───────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: oklch(0.25 0.02 145);
  color: white;
  padding: 10px 16px 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: all 200ms cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 100;
  box-shadow: 0 12px 32px oklch(0.20 0.05 145 / 0.3);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast code {
  font-family: var(--font-mono);
  background: oklch(0.35 0.02 145);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11.5px;
}

/* ─── Tweaks panel ────────────────────────────────────────── */

.tweaks {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 280px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 90;
  font-size: 13px;
  display: none;
}
.tweaks.open { display: block; }
.tweaks-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
}
.tweaks-head:active { cursor: grabbing; }
.tweaks-head h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.tweaks-body { padding: 12px 14px; }
.tweak-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}
.tweak-row + .tweak-row { border-top: 1px dashed var(--border); }
.tweak-row label {
  color: var(--ink-soft);
  font-size: 13px;
}
.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.seg button {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
}
.seg button.active {
  background: var(--accent);
  color: white;
}

/* ─── Scrollbars ─────────────────────────────────────────── */
.sidebar::-webkit-scrollbar,
.drawer-body::-webkit-scrollbar { width: 10px; }
.sidebar::-webkit-scrollbar-thumb,
.drawer-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid var(--bg);
}

/* Subtle entrance */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: none; }
}
.row { animation: fadeIn 180ms both; }

/* Smaller screens */

/* Tablet — sidebar gets narrower, padding reduced */
@media (max-width: 1100px) {
  .topbar { padding: 20px 24px 14px; gap: 16px; }
  .sidebar { padding-left: 24px; padding-right: 12px; }
  .main { padding-left: 24px; padding-right: 24px; }
  .brand-sub { display: none; }
}

/* Mobile — sidebar becomes a slide-out drawer, rows stack vertically */
@media (max-width: 820px) {
  :root { --row-h: auto; }

  .app {
    grid-template-columns: 1fr;
    max-width: none;
  }

  /* Topbar reflows into a tight two-row mobile layout */
  .topbar {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
  }
  .icon-btn.hamburger {
    display: inline-flex !important;
    position: relative;
    width: 38px;
    height: 38px;
    color: var(--ink);
    flex: 0 0 38px;
  }
  .icon-btn.hamburger:hover { background: var(--accent-soft); }
  .filter-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    display: none;
  }
  .filter-dot.on { display: block; }

  .brand { flex: 1 1 auto; min-width: 0; }
  .brand-title { font-size: 15px; }

  .brand-logo {
    height: 36px;
    padding: 2px 6px;
  }
  .brand-logo img { height: 24px; }

  /* Search drops to a full-width second row */
  .search {
    order: 5;
    flex: 1 0 100%;
    height: 42px;
    padding: 0 12px;
    margin-top: 2px;
  }
  .search input { font-size: 16px; } /* prevents iOS auto-zoom */
  .search-hint { display: none; }
  .search input::placeholder {
    /* Shorter placeholder on mobile via overflow */
    text-overflow: ellipsis;
  }

  /* Count + Clear share a row */
  .topbar-meta {
    order: 6;
    flex: 1 1 auto;
    font-size: 12.5px;
    padding-left: 4px;
  }
  .reset-all-btn {
    order: 7;
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
  }
  .reset-all-btn .btn-label { display: inline; }

  /* Sidebar → drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    max-width: 88vw;
    height: 100vh;
    background: var(--bg);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 70;
    padding: 16px 20px 80px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: block !important;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-head-mobile {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
  }
  .sidebar-head-mobile h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
  }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: oklch(0.20 0.05 280 / 0.4);
    z-index: 65;
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  /* Main column */
  .main {
    padding: 12px 12px 80px;
    min-width: 0;
  }

  /* Sticky table head off, but results-head still works as a label row */
  .results-head {
    display: none;
  }

  /* Rows: stack into a card-like layout */
  .row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "desc actions"
      "code actions"
      "unit actions";
    gap: 4px 12px;
    align-items: center;
    height: auto;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }
  .row .code-cell {
    grid-area: code;
    font-size: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .row .desc-cell {
    grid-area: desc;
    white-space: normal;
    text-overflow: clip;
    overflow: visible;
    font-size: 14.5px;
    line-height: 1.4;
  }
  .row .unit-cell {
    grid-area: unit;
    font-size: 11.5px;
    color: var(--muted);
  }
  .row-actions {
    grid-area: actions;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }
  .icon-btn {
    width: 38px;
    height: 38px;
  }
  .copy-btn {
    height: 38px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 8px;
  }

  /* Crumbs scroll horizontally */
  .crumbs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }
  .crumb { flex: 0 0 auto; }

  /* Facets stack */
  .facet-panel {
    padding: 12px 14px;
  }
  .facet-groups {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .facet-group {
    display: block;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--accent-soft-2);
  }
  .facet-group:last-child { border-bottom: 0; padding-bottom: 0; }
  .facet-label {
    margin-bottom: 6px;
    padding-top: 8px;
  }
  .facet-opt {
    padding: 6px 11px;
    font-size: 12.5px;
  }

  /* Recent strip */
  .recent-grid {
    grid-template-columns: 1fr;
  }

  /* Drawer = bottom sheet on mobile */
  .drawer {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: none;
    height: 88vh;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }
  .drawer.open { transform: translateY(0); }
  .drawer-head {
    padding: 20px 20px 14px;
    position: relative;
  }
  .drawer-head::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
  }

  /* Tweaks = bottom sheet on mobile */
  .tweaks {
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
  }

  /* Toast smaller */
  .toast {
    bottom: 16px;
    font-size: 12.5px;
    padding: 9px 14px 9px 12px;
    max-width: calc(100% - 32px);
  }
  .toast code { font-size: 11px; }

  /* Empty state more compact */
  .empty-state { padding: 48px 16px; }
}

/* Tiny phones — drop the brand title entirely */
@media (max-width: 380px) {
  .brand-title { display: none; }
  .topbar { padding: 8px 10px; }
  .main { padding: 10px 10px 80px; }
}

/* Touch-only: drop hover backgrounds that linger */
@media (hover: none) {
  .row:hover { background: transparent; }
  .row:active { background: var(--accent-soft); }
}
