/* ══════════════════════════════════════════════
   CATALOGUE PAGE — every class is prefixed .ctlg-
   Colours, radii and type come from the tokens of style.css.
   Wide screen: a nine-column table (fixed layout, so columns never move while filtering).
   Narrower than 920px (measured on the table's own box, not the window): each item becomes a card.
══════════════════════════════════════════════ */

/* .btn sets display:flex, which would beat the hidden attribute */
.ctlg [hidden] { display: none !important; }

.ctlg { padding-top: 4px; }
.ctlg-tabs { max-width: 560px; margin: 8px 0 0; }
.ctlg-tabs + .ctlg-panel .ctlg-head { margin-top: 20px; }

/* ── Head: title, Excel downloads, one line of explanation ── */
.ctlg-head { align-items: center; margin-bottom: 8px; }
.ctlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.ctlg-lede { max-width: 74ch; margin: 0 0 14px; color: var(--text-muted); font-size: var(--fs-sm); }
.ctlg-banner-sub { display: block; margin-top: 2px; font-size: var(--fs-sm); font-weight: 400; }

/* ── Toolbar ── */
.ctlg-toolbar { display: grid; grid-template-columns: minmax(220px, 1.5fr) minmax(0, 1fr) minmax(0, 1fr); gap: 10px 12px; align-items: center; }
.ctlg-toolbar .input, .ctlg-toolbar .select { height: 42px; }
.ctlg-search { position: relative; min-width: 0; }
.ctlg-search .input { padding-left: 40px; -webkit-appearance: none; appearance: none; }
.ctlg-search__icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); display: flex; color: var(--text-faint); pointer-events: none; }
.ctlg-select { min-width: 0; }

.ctlg-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ctlg-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px 0 10px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface);
  color: var(--text); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.ctlg-chip:hover { border-color: var(--accent); }
/* a ring that is always there, so a chip never changes width when it is switched on */
.ctlg-chip__box {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 18px; height: 18px; border: 1.5px solid var(--border-strong); border-radius: 50%; color: #fff;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.ctlg-chip__box svg { width: 11px; height: 11px; opacity: 0; }
.ctlg-chip[aria-pressed="true"] { background: var(--blue-tint); border-color: var(--accent); color: var(--blue-dark); }
.ctlg-chip[aria-pressed="true"] .ctlg-chip__box { background: var(--accent); border-color: var(--accent); }
.ctlg-chip[aria-pressed="true"] .ctlg-chip__box svg { opacity: 1; }

/* the row keeps its height whether or not the reset button shows */
.ctlg-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; min-height: 36px; margin: 10px 0 6px; }
.ctlg-count { color: var(--text-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

/* a page that is always tall enough keeps its scrollbar, so nothing shifts sideways when results shrink */
.ctlg-results { container-name: ctlg; container-type: inline-size; min-height: 70dvh; }

/* ── Table (wide) ── */
.ctlg-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: clip; }
.ctlg-table { table-layout: fixed; width: 100%; border-collapse: separate; border-spacing: 0; }
.ctlg-table col.k-code { width: 9%; }
.ctlg-table col.k-item { width: 18%; }
.ctlg-table col.k-preferred { width: 10%; }
.ctlg-table col.k-skus { width: 18.5%; }
.ctlg-table col.k-pack { width: 8.5%; }
.ctlg-table col.k-min { width: 7%; }
.ctlg-table col.k-stock { width: 7%; }
.ctlg-table col.k-status { width: 13%; }
.ctlg-table col.k-last { width: 9%; }

.ctlg-table thead th {
  position: sticky; top: var(--topbar-h); z-index: 2;
  padding: 11px 8px; background: var(--surface); box-shadow: inset 0 -1px 0 var(--border);
  border-bottom: 0; white-space: normal; vertical-align: bottom;
  font-size: 0.6875rem; letter-spacing: 0.02em; line-height: 1.25; overflow-wrap: break-word;
}
.ctlg-table thead th:first-child, .ctlg-table .ctlg-row > td:first-child { padding-left: 14px; }
.ctlg-table thead th:last-child, .ctlg-table .ctlg-row > td:last-child { padding-right: 14px; }
.ctlg-table .ctlg-row > td {
  padding: 10px 8px; vertical-align: top; font-size: var(--fs-sm); line-height: 1.4; overflow-wrap: anywhere;
}
.ctlg-table tbody tr:last-child > td { border-bottom: 0; }
.ctlg-row { cursor: pointer; }
.ctlg-row:focus-within > td { background: var(--blue-tint); }
.ctlg-table .cat-row > td { padding: 9px 14px; }
.ctlg-band__count { margin-left: 8px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--text-muted); }

.ctlg-table .c-id .gcode { font-size: var(--fs-base); }
.ctlg-table .c-name { font-size: var(--fs-base); }
.ctlg-inline-code { display: none; }
.ctlg-namebox { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ctlg-thumb {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 8px; overflow: hidden; background: #fff;
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
}
.ctlg-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.ctlg-thumb--none { background: var(--surface-2); color: var(--text-faint); }
.ctlg-thumb--big { width: 132px; height: 132px; border-radius: 12px; }
.ctlg-hero { display: flex; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
.ctlg-hero .ctlg-facts { flex: 1; min-width: 0; margin: 0; }
@media (max-width: 520px) {
  .ctlg-hero { flex-direction: column; }
  .ctlg-thumb--big { width: 100%; height: 160px; }
}
.ctlg-open {
  display: block; width: 100%; padding: 0; text-align: left; font: inherit; font-weight: 500; line-height: 1.35;
  color: var(--text); overflow-wrap: anywhere;
}
.ctlg-open:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.ctlg-dash, .ctlg-na { color: var(--text-faint); }
.ctlg-abs { color: var(--text-muted); font-style: italic; }
.ctlg-pack { overflow-wrap: anywhere; }
.ctlg-pack-sub { margin-top: 1px; font-size: var(--fs-xs); color: var(--text-muted); }
.ctlg-table .c-min, .ctlg-table .c-stock { font-size: var(--fs-base); }
.ctlg-table .c-last { color: var(--text-muted); }

.ctlg-table .badge { max-width: 100%; white-space: normal; text-align: left; line-height: 1.25; padding: 3px 9px; border-radius: 12px; }
.ctlg-short { display: block; margin-top: 3px; font-size: var(--fs-xs); color: var(--text-muted); }

/* SKU chips: "SUPPLIER · SKU", the preferred supplier's first */
.ctlg-skus { display: flex; flex-wrap: wrap; gap: 4px; }
/* when "SUPPLIER · SKU" does not fit on a line, the SKU moves to a second line instead of splitting a word */
.ctlg-sku {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 4px; max-width: 100%; padding: 2px 8px;
  border-radius: 12px; overflow-wrap: normal; background: var(--surface-2); color: var(--text);
  font-size: var(--fs-xs); line-height: 1.4; font-variant-numeric: tabular-nums;
}
.ctlg-sku__sup { font-weight: 500; }
.ctlg-sku__code { min-width: 0; overflow-wrap: anywhere; }
.ctlg-sku__dot { color: var(--text-faint); }
.ctlg-sku--pref { background: var(--blue-tint); color: var(--blue-dark); }
.ctlg-sku--pref .ctlg-sku__dot { color: var(--blue-dark); opacity: 0.6; }
.ctlg-sku--more { background: transparent; border: 1px dashed var(--border-strong); color: var(--text-muted); }
.ctlg-star { display: inline-flex; align-self: center; flex-shrink: 0; }
.ctlg-star svg { fill: currentColor; }

/* ── Cards: the table's own box is under 920px wide ── */
@container ctlg (max-width: 919px) {
  .ctlg-table, .ctlg-table tbody { display: block; width: auto; }
  .ctlg-table colgroup { display: none; }
  .ctlg-table thead {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
  }
  .ctlg-table .cat-row { display: block; }
  .ctlg-table .cat-row > td { display: block; padding: 9px 16px; }

  .ctlg-table .ctlg-row {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 16px;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
  }
  .ctlg-table tbody .ctlg-row:last-child { border-bottom: 0; }
  .ctlg-table .ctlg-row:hover { background: var(--surface-2); }
  .ctlg-table .ctlg-row:focus-within { background: var(--blue-tint); }
  .ctlg-table .ctlg-row > td { display: block; min-width: 0; text-align: left; }
  .ctlg-table .ctlg-row > td,
  .ctlg-table .ctlg-row > td:first-child,
  .ctlg-table .ctlg-row > td:last-child,
  .ctlg-table .ctlg-row:hover > td,
  .ctlg-table .ctlg-row:focus-within > td { padding: 0; border: 0; background: transparent; }
  .ctlg-table .ctlg-row > td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    font-size: var(--fs-xs); font-weight: 500; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-muted);
  }

  .ctlg-table .c-id { display: none !important; }
  .ctlg-table .ctlg-row > .c-name { display: flex; align-items: baseline; gap: 10px; grid-column: 1 / span 3; order: 1; }
  .ctlg-inline-code { display: inline-block; flex-shrink: 0; min-width: 3.9em; font-size: var(--fs-base); } /* names line up from card to card */
  .ctlg-table .c-name .ctlg-open { flex: 1; width: auto; }
  .ctlg-table .ctlg-row > .c-status { grid-column: 4; order: 2; display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
  .ctlg-table .c-status .ctlg-short { margin-top: 3px; }
  .ctlg-table .ctlg-row > .c-pref { order: 3; }
  .ctlg-table .ctlg-row > .c-pack { order: 4; }
  .ctlg-table .ctlg-row > .c-min { order: 5; }
  .ctlg-table .ctlg-row > .c-stock { order: 6; }
  .ctlg-table .ctlg-row > .c-skus { grid-column: 1 / span 3; order: 7; }
  .ctlg-table .ctlg-row > .c-last { order: 8; }
}

/* ── Cards on a phone: ID and name, supplier, status, minimum and stock; the rest is in the dialog ── */
@container ctlg (max-width: 559px) {
  .ctlg-table .ctlg-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; padding: 13px 14px; }
  .ctlg-table .ctlg-row > .c-name { grid-column: 1 / -1; }
  .ctlg-table .ctlg-row > .c-pref { grid-column: 1; order: 2; }
  .ctlg-table .ctlg-row > .c-status { grid-column: 2; order: 3; align-items: flex-start; text-align: left; align-self: end; }
  .ctlg-table .ctlg-row > .c-min { order: 4; }
  .ctlg-table .ctlg-row > .c-stock { order: 5; }
  .ctlg-table .ctlg-row > .c-skus, .ctlg-table .ctlg-row > .c-pack, .ctlg-table .ctlg-row > .c-last { display: none; }
  .ctlg-table .cat-row > td { padding: 9px 14px; }
}

/* ── Detail dialog ── */
.ctlg-modal:focus { outline: none; }
.ctlg-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; margin: 0 0 18px; }
.ctlg-facts--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ctlg-fact { min-width: 0; }
.ctlg-fact--wide { grid-column: 1 / -1; }
.ctlg-fact dt { margin: 0 0 2px; color: var(--text-muted); font-size: var(--fs-xs); font-weight: 500; letter-spacing: 0.03em; text-transform: uppercase; }
.ctlg-fact dd { margin: 0; font-size: var(--fs-base); overflow-wrap: anywhere; }
.ctlg-modal__h { margin: 4px 0 10px; font-size: var(--fs-base); font-weight: 500; }
.ctlg-modal .modal__body > p { margin: 0 0 18px; }
.ctlg-statusline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 14px; }
.ctlg-statusline .ctlg-short { display: inline; margin: 0; font-size: var(--fs-sm); }

.ctlg-skutable { margin: 0; }
.ctlg-skutable th, .ctlg-skutable td { padding: 9px 12px; font-size: var(--fs-sm); }
.ctlg-skutable td { overflow-wrap: anywhere; }
.ctlg-skutable th { white-space: normal; }
.ctlg-modal .table-wrap { margin-bottom: 18px; }
.ctlg-supcell { display: inline-flex; align-items: center; gap: 6px; }
.ctlg-modal .ctlg-star { color: var(--amber); }
.ctlg-star-gap { display: inline-block; width: 14px; flex-shrink: 0; }
.ctlg-link {
  padding: 0; text-align: left; font: inherit; font-weight: 500; color: var(--accent);
  text-decoration: underline; text-underline-offset: 3px;
}
.ctlg-link:hover { color: var(--blue-dark); }
.ctlg-modal__actions { margin-top: 20px; }

/* ── Smaller windows (the toolbar and the dialog; the table answers to its own width above) ── */
@media (max-width: 899px) {
  .ctlg-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ctlg-search { grid-column: 1 / -1; }
}
@media (max-width: 599px) {
  .ctlg-toolbar { grid-template-columns: minmax(0, 1fr); }
  .ctlg-actions { justify-content: flex-start; }
  .ctlg-facts--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ctlg-modal__actions .btn { flex: 1 1 100%; }
}
@media (pointer: coarse) {
  .ctlg-chip { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .ctlg-chip, .ctlg-chip__box { transition: none; }
}
