:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --ink: #17181a;
  --muted: #696c70;
  --line: #e5e6e8;
  --line-strong: #cfd1d4;
  --accent: #2c5e3f;
  --accent-ink: #ffffff;
  --accent-soft: #edf4ef;
  --warn: #9a3412;
  --radius: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --topbar: 60px;
  --font: "Schibsted Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}
html {
  scroll-padding-top: calc(var(--topbar) + var(--space-4));
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px / 1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.2;
}
a {
  color: inherit;
}
button,
input,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.muted {
  color: var(--muted);
}
.label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  background: rgb(250 250 250 / 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
  width: 280px;
  flex: none;
  white-space: nowrap;
}
.brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand span {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search {
  flex: 1;
  min-width: 0;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 38px;
  padding: 0 var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex: none;
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  height: 100%;
}
.search input::-webkit-search-cancel-button {
  cursor: pointer;
}
kbd {
  font: 12px var(--mono);
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 5px;
}
.chip {
  flex: none;
  height: 38px;
  padding: 0 var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--ink);
}
.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 320px;
  gap: var(--space-6);
  max-width: 1480px;
  margin: 0 auto;
  padding: var(--space-5);
}
.cats,
.summary {
  position: sticky;
  top: calc(var(--topbar) + var(--space-5));
  align-self: start;
  max-height: calc(100vh - var(--topbar) - 2 * var(--space-5));
  overflow: auto;
}

/* Category nav */
.cats {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.cats a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  color: var(--muted);
}
.cats a:hover {
  background: #f0f0f1;
  color: var(--ink);
}
.cats a.is-empty {
  opacity: 0.4;
}
.count {
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* Catalog */
.cat + .cat {
  margin-top: var(--space-6);
}
.cat h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
  padding-bottom: var(--space-2);
}
.cat h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin: var(--space-5) 0 var(--space-2);
}
.items {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.item {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 128px 128px 116px;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
}
.item + .item {
  border-top: 1px solid var(--line);
}
.item:hover {
  background: #f7f7f8;
}
.item.is-selected {
  background: var(--accent-soft);
}
.item.is-oos {
  color: var(--muted);
}
.code {
  font: 12.5px var(--mono);
  color: var(--muted);
  overflow-wrap: anywhere;
}
.name {
  font-weight: 500;
}
.note {
  display: block;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--muted);
}
.pack {
  font-size: 14px;
  color: var(--muted);
}
.price,
.totals td,
.stepper input,
.review-cat .amt,
.review-cat input,
.summary-bar strong,
.count {
  font-variant-numeric: tabular-nums;
}
.price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}
.price .per {
  font-size: 13px;
  color: var(--muted);
}
.price strong {
  font-weight: 600;
}
.price .sub {
  font-size: 12.5px;
  color: var(--muted);
}
.oos {
  justify-self: end;
  font-size: 13px;
  font-weight: 600;
  color: var(--warn);
}
.tag {
  display: inline-block;
  margin-left: var(--space-2);
  vertical-align: 1px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  background: #f0f0f1;
  color: var(--muted);
}
.tag--new {
  background: #fdecc8;
  color: #7a4b00;
}
.empty {
  padding: var(--space-6) 0;
  color: var(--muted);
}

/* Quantity stepper */
.stepper {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.stepper:focus-within {
  border-color: var(--accent);
}
.is-selected .stepper {
  border-color: var(--accent);
}
.stepper button {
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}
.stepper button:hover:not(:disabled) {
  background: #f0f0f1;
  color: var(--ink);
}
.stepper button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}
.stepper input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  text-align: center;
  background: none;
  font-weight: 600;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Summary */
.summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
}
.summary h2 {
  font-size: 17px;
  font-weight: 700;
}
.summary > p {
  margin: var(--space-3) 0 0;
  font-size: 14px;
}
.summary-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.totals {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-4);
  font-size: 14px;
}
.totals th {
  text-align: left;
  font-weight: 400;
  padding: 6px var(--space-3) 6px 0;
}
.totals td {
  text-align: right;
  white-space: nowrap;
  padding: 6px 0;
  vertical-align: top;
}
.totals tbody a {
  text-decoration: none;
}
.totals tbody a:hover {
  text-decoration: underline;
}
.totals tbody tr + tr {
  border-top: 1px solid var(--line);
}
.totals tfoot {
  border-top: 1px solid var(--line-strong);
  color: var(--muted);
}
.totals tfoot tr:first-child th,
.totals tfoot tr:first-child td {
  padding-top: var(--space-3);
}
.totals .grand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}
.totals .grand th {
  font-weight: 700;
}
.fine {
  font-size: 12.5px;
  color: var(--muted);
  margin: var(--space-3) 0 0;
}
.summary-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-5);
}
.summary-actions .btn--primary {
  flex: 1;
}
.summary-bar {
  display: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover {
  border-color: var(--ink);
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn--primary:hover {
  background: #234d33;
  border-color: #234d33;
}
.btn--quiet {
  border-color: transparent;
  background: none;
  color: var(--muted);
}
.btn--quiet:hover {
  color: var(--ink);
  border-color: transparent;
  background: #f0f0f1;
}
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
  color: var(--muted);
}
.icon-btn:hover {
  background: #f0f0f1;
  color: var(--ink);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Sized dialog primitive: .sheet + size modifier */
.sheet {
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.18);
  display: none;
  flex-direction: column;
}
.sheet[open] {
  display: flex;
}
.sheet::backdrop {
  background: rgb(20 22 24 / 0.45);
}
.sheet--confirm {
  width: min(440px, calc(100vw - 32px));
}
.sheet--form {
  width: min(640px, calc(100vw - 48px));
}
.sheet--editor {
  width: min(1120px, calc(100vw - 48px));
  height: min(880px, calc(100vh - 48px));
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  font-size: 18px;
}
.sheet-head .icon-btn {
  margin-left: auto;
}
.sheet-body {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--line);
}
.status {
  margin-right: auto;
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
}

/* Review */
.review-left {
  padding: var(--space-5);
  border-right: 1px solid var(--line);
  overflow: auto;
}
.review-right {
  padding: var(--space-5);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
}
.details {
  border: 0;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.details legend {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: var(--space-3);
  padding: 0;
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.field--address,
.field--notes {
  grid-column: 1 / -1;
}
.field input,
.field textarea {
  height: 38px;
  padding: 0 var(--space-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 400;
  font-size: 15px;
}
.field textarea {
  height: auto;
  padding: var(--space-2) var(--space-3);
  resize: vertical;
}
.field input:focus,
.field textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.review-lines {
  margin-top: var(--space-6);
}
.review-lines .label {
  margin-bottom: var(--space-2);
}
.review-cat + .review-cat {
  margin-top: var(--space-4);
}
.review-cat h4 {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 700;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line-strong);
}
.review-cat ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.review-cat li {
  display: grid;
  grid-template-columns: 56px 14px 96px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 0;
  font-size: 14px;
}
.review-cat li + li {
  border-top: 1px solid var(--line);
}
.review-cat input {
  width: 56px;
  height: 32px;
  text-align: center;
  font-weight: 600;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  -moz-appearance: textfield;
}
.review-cat input:focus {
  outline: 0;
  border-color: var(--accent);
}
.review-cat .unit {
  color: var(--muted);
  font-size: 13px;
}
.review-cat .amt {
  white-space: nowrap;
  font-weight: 600;
}
.email-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
}
.email {
  flex: 1;
  margin: 0;
  overflow: auto;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 12.5px / 1.6 var(--mono);
  white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* Medium: drop the category rail */
@media (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
  .cats {
    display: none;
  }
  .brand {
    width: auto;
  }
}

/* Narrow: single column, order bar at the bottom, full-screen review */
@media (max-width: 820px) {
  :root {
    --topbar: 100px;
  }
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-2) var(--space-3);
  }
  .brand {
    width: 100%;
  }
  .search {
    max-width: none;
  }
  kbd {
    display: none;
  }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: var(--space-4) var(--space-3) 96px;
  }
  .item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name stepper" "pack price" "code price";
    row-gap: 2px;
    padding: var(--space-3);
  }
  .item .name {
    grid-area: name;
  }
  .item .stepper {
    grid-area: stepper;
    width: 120px;
  }
  .item .code {
    grid-area: code;
  }
  .item .pack {
    grid-area: pack;
  }
  .item .price,
  .item .oos {
    grid-area: price;
    align-self: start;
  }
  .summary {
    position: static;
    max-height: none;
    padding: 0;
    border: 0;
    background: none;
  }
  .summary > :not(.summary-bar) {
    display: none;
  }
  .summary.has-items .summary-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    position: fixed;
    left: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
    z-index: 20;
    height: 56px;
    padding: 0 var(--space-2) 0 var(--space-4);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    background: var(--ink);
    color: #fff;
    font-size: 15px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
  }
  .summary-bar strong {
    margin-left: auto;
    font-size: 17px;
  }
  .summary-bar-cta {
    background: var(--accent);
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
  }
  .sheet--editor {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }
  .sheet-body {
    grid-template-columns: minmax(0, 1fr);
  }
  .review-left {
    border-right: 0;
    overflow: visible;
    border-bottom: 1px solid var(--line);
  }
  .review-right {
    min-height: 0;
  }
  .email {
    flex: none;
    overflow: visible;
  }
  .sheet-head {
    flex-wrap: wrap;
    row-gap: 0;
  }
  .sheet-head h2 {
    white-space: nowrap;
  }
  .sheet-head .muted {
    order: 3;
    width: 100%;
    font-size: 13px;
  }
  .sheet-foot .btn--primary {
    flex: 1;
  }
  .review-cat li {
    grid-template-columns: 56px 14px minmax(0, 1fr) auto;
    row-gap: 0;
  }
  .review-cat li > :is(input, .unit, .amt) {
    grid-row: span 2;
  }
  .review-cat li .name {
    grid-column: 3;
    grid-row: 1;
  }
  .review-cat li .code {
    grid-column: 3;
    grid-row: 2;
    font-size: 12px;
  }
  .details {
    grid-template-columns: 1fr;
  }
  .sheet-foot {
    flex-wrap: wrap;
  }
  .status {
    width: 100%;
  }
}
