:root {
  --brand: #8c1c20;
  --brand-dark: #681316;
  --ink: #251b1b;
  --muted: #6f6262;
  --surface: #ffffff;
  --canvas: #f4efec;
  --line: #e5d9d4;
  --focus: #d99b3f;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 0 18px 48px;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(140, 28, 32, .08), transparent 32rem),
    var(--canvas);
}

.site-hero {
  margin: 0 -18px;
  padding: 0;
  overflow: hidden;
  border-top: 5px solid var(--brand);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.site-hero .logo {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}

.site-hero .logo img {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: cover;
}

.mast {
  position: sticky;
  z-index: 100;
  top: 0;
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  margin: 0 -18px 18px;
  padding: 12px 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-top: 0;
  box-shadow: 0 8px 24px rgba(59, 35, 35, .1);
}

.mast .brand { display: none; }

.cart-summary {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 6px 16px rgba(140, 28, 32, .25);
  text-align: left;
}

.cart-summary span { display: block; font-size: 12px; opacity: .82; }
.cart-summary strong { display: block; margin-top: 2px; font-size: 22px; }
.cart-summary small { display: block; margin-top: 2px; font-size: 11px; opacity: .82; }

.cust {
  width: 100%;
  margin-left: 0;
  grid-template-columns: 82px minmax(130px, 190px) 82px minmax(150px, 220px);
  justify-content: end;
}

h1,
.note,
.bar,
#resultCount { max-width: 1500px; margin-left: auto; margin-right: auto; }

h1 { margin-top: 22px; color: var(--brand-dark); }

.bar {
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 5px 18px rgba(59, 35, 35, .08);
  backdrop-filter: blur(10px);
}

#q {
  flex: 1 1 320px;
  min-width: 180px;
  border: 1px solid #cdbdb7;
  border-radius: 8px;
  background: #fff;
}

#q:focus,
.qty-input:focus,
button:focus-visible,
.product-image:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 58%, transparent);
  outline-offset: 2px;
}

#resultCount {
  margin-top: 10px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

/* The catalogue table becomes a wrapping flex-card grid. */
#cat,
#cat tbody { display: block; width: 100%; }
#cat { max-width: 1500px; margin: 0 auto; border: 0; background: transparent; }
#cat thead { display: none; }
#cat tbody {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 16px;
}

#cat tbody tr {
  position: relative;
  display: flex;
  flex: 1 1 310px;
  flex-direction: column;
  min-width: 280px;
  max-width: calc(25% - 12px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 5px 16px rgba(59, 35, 35, .07);
  content-visibility: auto;
  contain-intrinsic-size: auto 520px;
  transition: transform .16s ease, box-shadow .16s ease;
}

#cat tbody tr:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(59, 35, 35, .12);
}

#cat td {
  display: block;
  width: auto;
  min-width: 0;
  border: 0;
  padding: 5px 14px;
  text-align: left;
}

#cat td:nth-child(1) {
  order: 2;
  padding-top: 12px;
  color: var(--brand);
  font-size: 13px;
  letter-spacing: .05em;
}

#cat td:nth-child(2) {
  order: 3;
  min-height: 52px;
  padding-top: 2px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
}

#cat td.img,
#cat td.img.set {
  order: 1;
  width: 100%;
  height: 220px;
  padding: 0;
  overflow: hidden;
  background: #faf8f6;
}

#cat td.img img,
#cat td.img.set img {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 12px;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform .2s ease;
}

#cat td.img img:hover { transform: scale(1.03); }

#cat td:nth-child(4),
#cat td:nth-child(5),
#cat td:nth-child(6),
#cat td:nth-child(7) {
  order: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 7px;
  padding-bottom: 7px;
  border-top: 1px solid #f0e8e5;
}

#cat td:nth-child(4)::before { content: "Carton qty"; }
#cat td:nth-child(5)::before { content: "Order qty"; }
#cat td:nth-child(6)::before { content: "Unit price"; }
#cat td:nth-child(7)::before { content: "Line total"; }

#cat td:nth-child(4)::before,
#cat td:nth-child(5)::before,
#cat td:nth-child(6)::before,
#cat td:nth-child(7)::before,
#cat td:nth-child(8)::before {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}

#cat td:nth-child(6)::after { content: " each"; color: var(--muted); font-size: 12px; }
#cat td.price::first-letter,
#cat td.total::first-letter { color: var(--muted); }
#cat td.price::before { margin-right: auto; }
#cat td.price { font-weight: 700; }
#cat td.price:not(:empty) { color: var(--ink); }
#cat td.total { color: var(--brand); font-size: 17px; font-weight: 800; }

.qty-input {
  width: 88px;
  padding: 8px 10px;
  border: 1px solid #cdbdb7;
  border-radius: 7px;
  text-align: right;
  background: #fffdfb;
}

#cat td.notes {
  order: 5;
  min-width: 0;
  min-height: 42px;
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px solid #f0e8e5;
  color: var(--muted);
}

#cat td.notes:empty::after { content: "Add a note…"; color: #aa9d98; }

.image-modal {
  width: min(92vw, 980px);
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}

.image-modal::backdrop { background: rgba(27, 17, 17, .78); backdrop-filter: blur(4px); }
.modal-image-wrap { display: grid; place-items: center; min-height: 300px; max-height: 76vh; padding: 20px; background: #f8f5f3; }
.modal-image-wrap img { max-width: 100%; max-height: 70vh; object-fit: contain; }
.modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; }
.modal-footer strong { color: var(--brand); }
.modal-close { flex: 0 0 auto; }

.no-results {
  width: 100%;
  padding: 38px;
  border: 1px dashed #cdbdb7;
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, .65);
}

@media (max-width: 1180px) {
  #cat tbody tr { max-width: calc(33.333% - 11px); }
}

@media (max-width: 860px) {
  body { padding-left: 12px; padding-right: 12px; }
  .site-hero { margin-left: -12px; margin-right: -12px; }
  .mast {
    grid-template-columns: minmax(140px, 190px) minmax(0, 1fr);
    margin-left: -12px;
    margin-right: -12px;
  }
  .mast .cust {
    grid-template-columns: 76px minmax(90px, 1fr) 76px minmax(90px, 1fr);
  }
  #cat tbody tr { max-width: calc(50% - 8px); }
}

@media (max-width: 570px) {
  .mast { grid-template-columns: 120px minmax(0, 1fr); align-items: start; }
  .mast .cust { grid-template-columns: 72px minmax(0, 1fr); }
  .cart-summary { position: sticky; top: 12px; }
  .cart-summary strong { display: inline; }
  #cat tbody tr { min-width: 100%; max-width: 100%; }
  #cat td.img, #cat td.img.set { height: 250px; }
}

@media print {
  body { padding: 0; background: #fff; }
  .mast { position: static; box-shadow: none; }
  #cat tbody { gap: 8px; }
  #cat tbody tr { max-width: calc(33.333% - 6px); break-inside: avoid; box-shadow: none; }
  .image-modal, #resultCount { display: none; }
}
