/* Buttons */
/* :where() keeps the bare submit-button default at zero specificity, so every .btn-* variant overrides it. */
.btn, :where(button[type=submit]:not(.btn-text)), .button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-height); padding: 0 var(--space-4); border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  background: var(--primary-strong); color: var(--on-primary);
}
/* The primary hover is limited to elements that are not a variant, so the variant hovers below always win. */
.btn:not(.btn-secondary):not(.btn-danger):not(.btn-text):hover,
button[type=submit]:not([class*="btn-"]):hover { background: var(--primary-stronger); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-subtle); text-decoration: none; }
.btn-danger { background: var(--danger-fg); color: var(--on-primary); }
.btn-danger:hover { background: var(--danger-strong); text-decoration: none; }
.btn-text { background: none; border: 0; color: var(--primary-strong); padding: 0; min-height: 0;
  font-weight: 500; cursor: pointer; }
.btn-text:hover { text-decoration: underline; background: none; }
.btn-sm { min-height: 28px; padding: 0 var(--space-3); font-size: 13px; }
.btn[disabled], button[disabled] { opacity: .55; cursor: not-allowed; }

/* Layout helpers */
.stack > * + * { margin-top: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.cluster form { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-1); }
.card + .card, .grid-2 + .card, .card + .grid-2, .grid-2 + .grid-2 { margin-top: var(--space-4); }
.grid-2 > .card + .card { margin-top: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.card-header h2 { margin: 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); }
.card-body { padding: var(--space-4); }
.card-body > :last-child { margin-bottom: 0; }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th { background: var(--surface-subtle); text-align: left; font-size: 12px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
  padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); vertical-align: middle;
  overflow-wrap: anywhere; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-subtle); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .cell-thumb { width: 56px; }
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-subtle); display: block; flex: none; max-width: none; }
/* Whole-row links: app.js follows the row's a.stretched on click; the link itself stays the keyboard target. */
.row-link { cursor: pointer; }
.cell-title { font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.cell-sub { display: block; font-size: 12px; color: var(--text-muted); }
.table-footer { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  flex-wrap: wrap; padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); }

/* Definition list */
.dl { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: var(--space-2) var(--space-4); margin: 0; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) { .dl { grid-template-columns: 1fr; } .dl dd { margin-bottom: var(--space-2); } }

/* Badges and chips */
.badge { display: inline-flex; align-items: center; gap: var(--space-1); border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral-fg); }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0 0; padding: 0; list-style: none; }
.chip { display: inline-flex; align-items: center; gap: var(--space-2); background: var(--primary-soft);
  color: var(--primary-strong); border-radius: var(--radius-sm); padding: 2px var(--space-2); font-size: 13px; }
.chip a { color: inherit; font-weight: 700; }
.chip-warning { background: var(--warning-bg); color: var(--warning-fg); }

/* Tabs */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-4);
  overflow-x: auto; }
.tab { padding: var(--space-2) var(--space-3); color: var(--text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--primary-strong); border-bottom-color: var(--primary); font-weight: 600; }
.tab-count { margin-left: var(--space-1); background: var(--neutral-bg); color: var(--neutral-fg);
  border-radius: 10px; padding: 0 6px; font-size: 12px; }

/* Pager */
.pager { display: flex; align-items: center; gap: var(--space-3); font-size: 13px; color: var(--text-muted); }
.pager a { padding: var(--space-1) var(--space-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); }
.pager a:hover { text-decoration: none; background: var(--surface-subtle); }

/* Alerts */
.alert { border-radius: var(--radius); padding: var(--space-3) var(--space-4); border: 1px solid transparent;
  background: var(--info-bg); color: var(--info-fg); margin-bottom: var(--space-3); }
.alert ul { margin: var(--space-1) 0 0; padding-left: var(--space-5); }
.alert-success { background: var(--success-bg); color: var(--success-fg); }
.alert-error { background: var(--danger-bg); color: var(--danger-fg); }
.alert-warning { background: var(--warning-bg); color: var(--warning-fg); }

/* Empty state */
.empty { text-align: center; padding: var(--space-8) var(--space-4); color: var(--text-muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: var(--space-1); }

/* Filter bar */
.filter-bar { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.filter-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: flex-end; }
.filter-row .field-inline { display: flex; flex-direction: column; gap: 2px; }
.filter-row .field-inline label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.filter-row .grow { flex: 1 1 240px; }
.filter-row .grow input { width: 100%; }
.filter-more { margin-top: var(--space-2); }
.filter-more summary { cursor: pointer; color: var(--primary-strong); font-weight: 500; font-size: 13px; }
.filter-more[open] .filter-row { margin-top: var(--space-2); }
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 400; min-height: var(--control-height); }

/* Forms */
.form-stack { max-width: 640px; }
.form-field { margin-bottom: var(--space-4); }
.form-field > label:not(.check) { display: block; margin-bottom: var(--space-1); }
.form-field input:not([type=checkbox]):not([type=radio]), .form-field select, .form-field textarea { width: 100%; }
.form-actions { position: sticky; bottom: 0; display: flex; gap: var(--space-2); align-items: center;
  background: var(--surface); border-top: 1px solid var(--border); padding: var(--space-3) var(--space-4);
  margin: var(--space-4) calc(-1 * var(--space-4)) calc(-1 * var(--space-4)); border-radius: 0 0 var(--radius) var(--radius); }

/* Product media */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
.gallery a, .gallery > img { display: block; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow: hidden; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.image-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3);
  list-style: none; padding: 0; margin: 0; }
.image-list li { cursor: grab; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-2); text-align: center; }
.image-list img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; margin-bottom: var(--space-2); }
.product-head { display: flex; gap: var(--space-4); align-items: center; min-width: 0; }
.product-head .thumb { width: 64px; height: 64px; }
.product-head > * { min-width: 0; overflow-wrap: anywhere; }
.price-lg { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Category tree */
.tree { list-style: none; margin: 0; padding: 0; }
.tree li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tree li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.tree li:last-child { border-bottom: 0; }
.tree li.tree-empty { display: block; border: 0; padding: 0; }
.tree .tree-actions { opacity: 0; }
.tree li:hover .tree-actions, .tree li:focus-within .tree-actions { opacity: 1; }
/* touch screens have no hover: show the actions all the time */
@media (hover: none) {
  .tree .tree-actions { opacity: 1; }
}
.depth-1 { padding-left: calc(var(--space-4) + 24px) !important; }
.depth-2 { padding-left: calc(var(--space-4) + 48px) !important; }
.depth-3 { padding-left: calc(var(--space-4) + 72px) !important; }
.depth-4 { padding-left: calc(var(--space-4) + 96px) !important; }
.depth-5 { padding-left: calc(var(--space-4) + 120px) !important; }

/* Matching */
.match { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--space-4); }
@media (max-width: 900px) { .match { grid-template-columns: 1fr; } }
.candidate { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); }
.candidate + .candidate { margin-top: var(--space-2); }

/* Codes and rich text */
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); list-style: none;
  padding: 0; font-family: var(--mono); font-size: 15px; }
.codes li { background: var(--surface-subtle); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--space-2); text-align: center; }
.qr-setup { display: flex; gap: var(--space-5); align-items: center; flex-wrap: wrap; }
.rich { line-height: 1.65; max-width: 75ch; }
.rich table { border-collapse: collapse; }
.rich td, .rich th { border: 1px solid var(--border); padding: var(--space-1) var(--space-2); }
.errorlist.nonfield { background: var(--danger-bg); color: var(--danger-fg); border-radius: var(--radius);
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); }
.codes-single { font-size: 16px; overflow-wrap: anywhere; }
.chips-bar { padding: 0 var(--space-4); margin-bottom: var(--space-3); }
.lock-list { list-style: none; padding: 0; margin: 0; } .lock-list li { display: inline-flex; align-items: center; gap: var(--space-2); }
.match + .match { border-top: 1px solid var(--border); padding-top: var(--space-4); }
.match h2 { font-size: 15px; overflow-wrap: anywhere; }
.candidate-meta { margin: var(--space-2) 0; }
.candidate form { margin: 0; }
.input-xs { width: 4rem; }
a.badge:hover { text-decoration: none; filter: brightness(.97); }
.nowrap { white-space: nowrap; }
.feed-label { min-width: 12rem; }
pre.value { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12px; max-height: 12rem; overflow: auto; }
.changes { margin: 0; padding-left: var(--space-4); }
.table-wrap > .table { min-width: 640px; }  /* narrow screens scroll the table instead of crushing columns */
.bulk-sale { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); background: var(--primary-soft); }
.bulk-sale summary { cursor: pointer; font-weight: 600; }
.bulk-sale form { margin-top: var(--space-3); }
.bulk-sale .helptext { flex-basis: 100%; margin: 0; }
