.page.order-page {
  width: min(1540px, calc(100% - 24px));
  margin: 18px auto 36px;
}

.order-sheet {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 6px 22px rgba(25, 35, 31, .06);
}

.order-editor-head,
.lines-toolbar,
.order-lines-foot,
.order-savebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.order-editor-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #faf9f5;
}

.order-editor-head .eyebrow { margin-bottom: 2px; }
.order-editor-head h1 { margin: 0; font-size: 23px; line-height: 1.15; letter-spacing: -.025em; }
.order-editor-actions,
.order-savebar > div { display: flex; gap: 7px; }
.button.compact { min-height: 34px; padding: 5px 12px; border-radius: 7px; font-size: 13px; }

.order-meta-grid {
  display: grid;
  grid-template-columns: minmax(120px, .8fr) minmax(145px, 1fr) minmax(145px, 1fr) repeat(2, minmax(130px, .9fr)) minmax(135px, .9fr) minmax(175px, 1.15fr);
  gap: 8px 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.compact-field { min-width: 0; }
.compact-field.field-title { grid-column: span 2; }
.compact-field.field-notes { grid-column: 1 / -1; }
.compact-field label,
.line-cell label {
  display: block;
  margin: 0 0 3px;
  color: #5f6965;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .055em;
  line-height: 1.1;
  text-transform: uppercase;
}

.compact-field input,
.compact-field select,
.compact-field textarea,
.line-cell input,
.line-cell select {
  width: 100%;
  height: 32px;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid #cfcfc9;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.compact-field textarea { height: 45px; min-height: 45px; resize: vertical; }
.compact-field input:focus,
.compact-field select:focus,
.compact-field textarea:focus,
.line-cell input:focus,
.line-cell select:focus { border-color: var(--green); outline: 2px solid rgba(31, 102, 80, .12); }
.errorlist { margin: 2px 0 0; padding: 0; list-style: none; font-size: 11px; }
.form-banner { margin: 10px 16px 0; padding: 8px 10px; border-radius: 5px; background: #fff0ef; }

.order-lines-panel { padding: 0 16px; }
.order-single-line { padding-top: 12px; }
.lines-toolbar { min-height: 42px; }
.lines-toolbar strong { font-size: 15px; }
.order-lines-scroll { overflow-x: auto; border-radius: 6px 6px 0 0; }
.order-lines-scroll:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.order-line-head,
.order-line-row {
  display: grid;
  grid-template-columns: minmax(158px, 1.1fr) minmax(150px, 1.65fr) 275px 55px 86px minmax(125px, .65fr) 124px 75px 30px;
  min-width: 1144px;
  gap: 6px;
  align-items: start;
}

.historical-sale-meta {
  grid-template-columns: 145px 190px minmax(240px, 1fr);
}
.historical-sale-meta .field-title { grid-column: auto; }
.historical-sale-meta .field-notes { grid-column: 1 / -1; }
.historical-sale-hint {
  margin-bottom: 0;
  background: #edf7f2;
  color: #315c4d;
  font-size: 11px;
}
.historical-line-head,
.historical-line-row {
  grid-template-columns: minmax(165px, 1fr) minmax(180px, 1.65fr) 70px 105px 95px 30px;
  min-width: 690px;
}

.order-line-head {
  padding: 6px 7px;
  border: 1px solid #d9d8d2;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: #efeee9;
  color: #5f6965;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.order-line-row {
  padding: 4px 7px;
  border: 1px solid #e1e0da;
  border-bottom: 0;
  background: #fff;
}

.order-line-row:nth-child(even) { background: #fbfaf7; }
.order-line-row:last-child { border-bottom: 1px solid #e1e0da; }
.order-line-head > :nth-last-child(2) { text-align: right; padding-right: 3px; }
.line-cell { min-width: 0; }
.line-cell label:not(.price-override), .order-dialog .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.manual-cell [data-manual-fields] {
  display: grid;
  grid-template-columns: 53px minmax(0, 1fr) auto 24px;
  gap: 5px;
  align-items: start;
}
.manual-cell [data-manual-fields][hidden] { display: none; }
.line-cell label.price-override {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  margin: 0;
  font-size: 11px;
  text-transform: none;
  letter-spacing: normal;
  white-space: nowrap;
  cursor: pointer;
}
.price-override input { width: 14px; height: 14px; margin: 0; }
.manual-quote-toggle {
  width: 24px;
  height: 24px;
  margin-top: 4px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--green);
  font-weight: 800;
  cursor: pointer;
}
.manual-quote-toggle:hover,
.manual-quote-toggle[aria-expanded="true"] { background: var(--green-2); }
.manual-quote { grid-column: 3 / 8; width: fit-content; padding: 4px 7px; border-radius: 5px; background: var(--green-2); font-size: 12px; }
.line-cell input[readonly] { background: #edf7f2; }
.pricing-rule { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr auto; gap: 12px; margin: 12px 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.pricing-rule[hidden] { display: none; }
.pricing-rule label { display: block; margin-bottom: 5px; }
.pricing-rule input:not([type="checkbox"]), .pricing-rule select { width: 100%; min-height: 36px; }
.pricing-remove { align-self: end; }
.pricing-remove input { display: none; }
.line-total { padding: 7px 3px 0; text-align: right; white-space: nowrap; font-size: 12px; font-weight: 800; }
.line-remove { position: relative; }
.line-remove input { display: none; }
.line-remove button {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #9c342e;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.line-remove button:hover { border-color: #e7c4c1; background: #fff0ef; }
.line-errors { grid-column: 1 / -1; color: var(--red); font-size: 11px; }

.order-lines-foot { padding: 8px 2px 10px; font-size: 13px; }
.order-lines-foot strong { display: inline-block; min-width: 90px; margin-left: 10px; text-align: right; font-size: 16px; }
.inline-add { border: 0; background: none; color: var(--green); cursor: pointer; font-size: 12px; font-weight: 800; }

.order-savebar {
  position: sticky;
  bottom: 0;
  z-index: 2;
  min-height: 48px;
  padding: 7px 16px;
  border-top: 1px solid var(--line);
  background: rgba(250, 249, 245, .97);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  .order-meta-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .compact-field.field-title { grid-column: span 2; }
}

@media (max-width: 720px) {
  .page.order-page { width: min(100% - 16px, 1540px); margin-top: 10px; }
  .order-editor-head { align-items: flex-start; }
  .order-editor-actions { display: none; }
  .order-editor-head h1 { font-size: 19px; }
  .order-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px; }
  .compact-field.field-title,
  .compact-field.field-notes { grid-column: 1 / -1; }
  .order-lines-panel { padding-inline: 10px; }
  .historical-sale-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .historical-sale-meta .field-title,
  .historical-sale-meta .field-notes { grid-column: 1 / -1; }
  .order-savebar > span { display: none; }
  .order-savebar { justify-content: flex-end; }
  .pricing-rule { grid-template-columns: 1fr 1fr; }
  .pricing-remove { grid-column: 1 / -1; }
}

.catalogue-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid #cfcfc9;
  border-radius: 5px;
  background: #fff;
  color: var(--green);
  font-size: 13px;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}
.catalogue-trigger:hover { border-color: var(--green); }
.catalogue-trigger span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catalogue-chevron { flex: 0 0 6px; height: 6px; margin: 0 2px 3px 0; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.catalogue-trigger[hidden], [data-product-field][hidden] { display: none; }
.order-line-row[hidden] { display:none; }
.order-dialog { width: min(590px, calc(100% - 24px)); max-height: calc(100dvh - 24px); border: 1px solid var(--line); border-radius: 12px; padding: clamp(14px, 4vw, 24px); color: var(--ink); }
.order-dialog::backdrop { background: rgba(20,25,23,.45); }
#catalogue-dialog-title { margin: 0 0 12px; }
#order-catalogue-picker > label { display: block; font-size: 13px; font-weight: 700; }
#catalogue-search,
#catalogue-results { display: block; width: 100%; margin-top: 5px; padding: 6px; border: 1px solid #cfcfc9; border-radius: 5px; background: #fff; color: var(--ink); }
#catalogue-results option { padding: 4px; white-space: nowrap; }
#catalogue-empty { margin: 4px 0 0; color: var(--muted); }
.catalogue-dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.catalogue-dialog-actions [disabled] { opacity: .5; cursor: default; }
.catalogue-picker-actions { justify-content: space-between; }
.catalogue-delete { color: #9c342e; }
#catalogue-action-status { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
#catalogue-action-status:empty { display: none; }
#order-product-create { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
#product-create-title { margin: 0 0 8px; font-size: 16px; }
.product-create-grid { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 1fr) 110px; gap: 8px; }
.product-create-grid label { display: grid; gap: 3px; min-width: 0; font-size: 13px; font-weight: 700; }
.product-create-grid input, .product-create-grid select { width: 100%; min-width: 0; height: 34px; padding: 4px 6px; border: 1px solid #cfcfc9; border-radius: 5px; background: #fff; color: var(--ink); font-weight: 400; }
.product-create-subtype, .product-create-description { grid-column: span 2; }
#product-duplicate { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 7px; margin-top: 8px; padding: 8px; border-radius: 6px; background: var(--green-2); color: var(--green); }
#product-duplicate[hidden], #product-use-duplicate[hidden] { display: none; }
#product-duplicate-status { flex: 1 1 220px; margin: 0; font-size: 13px; }
#product-create-error { margin: 6px 0 0; color: var(--red); font-size: 13px; }
#product-create-error:empty { display: none; }
@media (max-width: 425px) {
  .product-create-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .product-create-subtype { grid-column: auto; }
}
