

#custom-orders .utility-actions.customer-actions {
  grid-template-columns: auto 40px;
  gap: 10px;
}
#newCustomOrderButton {
  padding: 4px 12px;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}
.custom-order-no { font-size: 14px; color: #3656a8; font-weight: 600; }
.custom-order-status { font-size: 13px; color: #8b6b1f; font-weight: 600; margin-top: 4px; }
.custom-order-grid {
  display: grid;
  grid-template-columns: minmax(190px, 0.55fr) minmax(360px, 1.2fr) minmax(430px, 1.4fr);
  gap: 14px;
  align-items: start;
}
.custom-order-grid > .custom-order-panel:nth-child(1) { order: 2; }
.custom-order-grid > .custom-order-panel:nth-child(2) { order: 1; }
.custom-order-grid > .custom-order-panel:nth-child(3) { order: 3; }
@media (max-width: 1100px) {
  .custom-order-grid { grid-template-columns: 1fr; }
  .custom-order-grid > .custom-order-panel:nth-child(1),
  .custom-order-grid > .custom-order-panel:nth-child(2),
  .custom-order-grid > .custom-order-panel:nth-child(3) { order: initial; }
}
.custom-order-panel {
  background: #fff;
  border: 1px solid #e2e6ee;
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 0;
}
.custom-order-field input, .custom-order-field textarea, .custom-order-field select { box-sizing: border-box; min-width: 0; }
.custom-order-h3 {
  margin: 14px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #5a6478;
}
.custom-order-h3:first-child { margin-top: 0; }
.custom-order-field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.custom-order-field label { font-size: 11px; color: #6b7484; }
.custom-order-field input, .custom-order-field textarea, .custom-order-field select {
  padding: 6px 8px; border: 1px solid #cdd4e0; border-radius: 6px; font-size: 13px; width: 100%;
}
.custom-order-field-row { display: flex; gap: 10px; }
.custom-order-field-row .custom-order-field { flex: 1; }

@media (max-width: 640px) {
  /* Let multi-field rows (e.g. Order/Fitting/Ready dates) wrap and shrink
     instead of overflowing their container on narrow screens. */
  .custom-order-field-row { flex-wrap: wrap; }
  .custom-order-field-row .custom-order-field { flex: 1 1 140px; min-width: 0; }
  .custom-order-field-row .custom-order-field input,
  .custom-order-field-row .custom-order-field select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
}
.custom-measure-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.custom-measure-field { display: flex; flex-direction: column; gap: 2px; }
.custom-measure-field label { font-size: 11px; color: #6b7484; }
.custom-measure-field input { padding: 5px 7px; border: 1px solid #cdd4e0; border-radius: 6px; font-size: 13px; }
.custom-items-block { display: flex; gap: 14px; }
.custom-items-col { flex: 1; }
.custom-items-title { font-weight: 600; font-size: 12px; margin-bottom: 6px; color: #3656a8; }
.custom-item-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.custom-item-name { flex: 1; font-size: 13px; }
.custom-item-qty { width: 52px; padding: 3px 5px; border: 1px solid #cdd4e0; border-radius: 5px; font-size: 12px; }
.custom-item-empty { font-size: 12px; color: #98a0b0; }


.custom-measure-grid-sm {
  grid-template-columns: repeat(2, minmax(0, 72px));
  justify-content: center;
  gap: 6px 8px;
}
.custom-measure-grid-sm .custom-measure-field { min-width: 0; }
.custom-measure-grid-sm .custom-measure-field label { font-size: 10px; }
.custom-measure-grid-sm .custom-measure-field input {
  width: 72px;
  min-width: 0;
  box-sizing: border-box;
  padding: 3px 4px;
  font-size: 12px;
}


.custom-additem-row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.custom-additem-row select { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid #cdd4e0; border-radius: 6px; font-size: 13px; }
.custom-additem-row .ts-wrapper { flex: 1; min-width: 0; }
.custom-additem-row input { width: 70px; padding: 6px 6px; border: 1px solid #cdd4e0; border-radius: 6px; font-size: 13px; }
.custom-item-type-pill { float: right; color: #3656a8; font-size: 11px; font-weight: 600; margin-left: 10px; }
.custom-items-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.custom-items-table th { text-align: left; font-size: 12px; color: #6b7484; border-bottom: 1px solid #e2e6ee; padding: 3px 5px; }
.custom-items-table td { padding: 3px 5px; border-bottom: 1px solid #f0f2f6; }
.custom-items-table td:nth-child(3), .custom-items-table td:nth-child(4), .custom-items-table td:nth-child(5) { text-align: right; }
.custom-item-remove { color: #b42318; }
.custom-goto-draw-row { margin-top: 12px; display: flex; justify-content: flex-end; }
.item-master-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.item-group-bg-thumb {
  display: inline-flex;
  width: 34px;
  height: 34px;
  border: 1px solid #c6dce5;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.item-group-bg-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#custom-order-preparation .custom-workshop-table {
  table-layout: fixed;
  width: 100%;
  min-width: 0;
}
#custom-order-preparation .custom-workshop-table th,
#custom-order-preparation .custom-workshop-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#custom-order-preparation .custom-workshop-table th:last-child,
#custom-order-preparation .custom-workshop-table td:last-child {
  width: 42px;
  text-align: center;
}

.custom-prep-draw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.custom-prep-draw-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.custom-prep-draw-tools .draw-tool {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #687790;
}
.custom-prep-draw-tools .small-button[aria-pressed="true"] {
  background: linear-gradient(#d8e5fb, var(--button));
  color: #1a3154;
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.custom-prep-draw-tools { gap: 5px; }
.custom-prep-draw-tools .small-button {
  font-size: 11px;
  padding: 3px 8px;
  white-space: nowrap;
}
.custom-prep-draw-tools .draw-tool { font-size: 11px; gap: 3px; }
.custom-prep-draw-tools input[type="range"] { width: 90px; }
.custom-prep-drawing-stage {
  position: relative;
  margin: 8px auto 0;
  border: 1px solid #e2e6ee;
  border-radius: 6px;
  background: #fff;

  width: 100%;
  max-width: 100%;
  aspect-ratio: 1000 / 700;
  overflow: hidden;
  touch-action: none;
}
.custom-prep-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
}
.custom-prep-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}
.custom-prep-overlay path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.custom-prep-drawing-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8a93a3;
  font-size: 13px;
  padding: 24px;
  text-align: center;
}
.custom-prep-drawing-empty[hidden] {
  display: none;
}

.custom-workshop-panel { margin-top: 16px; width: 100%; min-width: 0; }
.custom-workshop-wrap { max-height: 260px; overflow: auto; }
.custom-workshop-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.custom-workshop-table th {
  text-align: left;
  color: #6b7484;
  border-bottom: 1px solid #e2e6ee;
  padding: 4px 6px;
}
.custom-workshop-table td {
  border-bottom: 1px solid #f0f2f6;
  padding: 4px 6px;
}

#customWorkshopPanel .custom-workshop-table th:first-child,
#customWorkshopPanel .custom-workshop-table td:first-child {
  width: 72px;
  text-align: left;
  white-space: nowrap;
}
#customWorkshopPanel .custom-workshop-table .custom-workshop-actions {
  text-align: left;
  white-space: nowrap;
}
#customWorkshopPanel .custom-workshop-table th:nth-child(2),
#customWorkshopPanel .custom-workshop-table td:nth-child(2) {
  width: 70px;
}
#customWorkshopPanel .custom-workshop-table th:nth-child(3),
#customWorkshopPanel .custom-workshop-table td:nth-child(3) {
  width: 70px;
}
#customWorkshopPanel .custom-workshop-table th:nth-child(4),
#customWorkshopPanel .custom-workshop-table td:nth-child(4) {
  width: 56px;
}
#customWorkshopPanel .custom-workshop-table th:nth-child(5),
#customWorkshopPanel .custom-workshop-table td:nth-child(5) {
  width: 34px;
  text-align: center;
}

.custom-items-wrap {
  max-height: 260px;
  border: 0;
  overflow: auto;
}

.custom-workshop-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
}
.custom-workshop-prep-button {
  min-width: 32px;
  width: auto;
  height: 26px;
  padding: 2px 8px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #d2a000;
  border-radius: 6px;
  background: #ffd75a;
  color: #473200;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.custom-workshop-prep-button:hover,
.custom-workshop-prep-button:focus {
  background: #ffc928;
}

@media (max-width: 1024px), (pointer: coarse) {
  .custom-workshop-prep-button {
    min-width: 44px;
    height: 36px;
    padding: 6px 14px;
    font-size: 15px;
    border-radius: 8px;
  }
}
.custom-prep-info {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}


.custom-prep-grid {
  grid-template-columns: minmax(240px, 0.55fr) minmax(430px, 1.6fr);
  gap: 8px;
}
.custom-prep-grid > .custom-order-panel:nth-child(1) {
  grid-column: 1 / -1;
  order: 0;
}
.custom-prep-grid > .custom-order-panel:nth-child(2) { order: 1; }
.custom-prep-grid > .custom-order-panel:nth-child(3) { order: 2; }
.custom-prep-customer-panel .custom-prep-info {

  grid-template-columns: repeat(6, minmax(0, 1fr)) 1.5fr;
  gap: 6px;
}
.custom-prep-customer-panel .custom-prep-notes-field {
  grid-column: auto;
}

.custom-prep-customer-panel .custom-prep-info div { padding: 3px 7px; }
.custom-prep-customer-panel .custom-prep-info span { font-size: 9px; }
.custom-prep-customer-panel .custom-prep-info strong { font-size: 11px; min-height: 13px; }

.custom-prep-grid .custom-order-h3 {
  display: none;
}

#custom-order-preparation .customer-header {
  padding: 6px 18px;
}
#custom-order-preparation .custom-prep-grid {
  margin-top: 8px;
}
#custom-order-preparation .custom-prep-customer-panel {
  padding-top: 8px;
}

.custom-prep-grid > .custom-order-panel:nth-child(3) .custom-workshop-panel:first-child {
  margin-top: 0;
}


.custom-prep-grid .custom-measure-grid-sm {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.custom-prep-grid .custom-prep-measure {
  padding: 3px 6px;
}
.custom-prep-grid .custom-prep-measure span { font-size: 10px; }
.custom-prep-grid .custom-prep-measure input { font-size: 12px; padding: 1px 4px; }
@media (max-width: 1100px) {
  .custom-prep-grid { grid-template-columns: 1fr; }
  .custom-prep-grid > .custom-order-panel:nth-child(1),
  .custom-prep-grid > .custom-order-panel:nth-child(2),
  .custom-prep-grid > .custom-order-panel:nth-child(3) { order: initial; }
  .custom-prep-customer-panel .custom-prep-info { grid-template-columns: repeat(6, minmax(0, 1fr)) 1.5fr; }
}
.custom-prep-info div,
.custom-prep-measure,
.custom-prep-notes {
  border: 1px solid #d9e7ee;
  background: #f9fcfd;
  border-radius: 6px;
  padding: 6px 8px;
}
.custom-prep-info span,
.custom-prep-measure span {
  display: block;
  color: #4c6280;
  font-size: 11px;
}
.custom-prep-info strong,
.custom-prep-measure strong {
  display: block;
  min-height: 18px;
  color: #002f45;
  font-size: 13px;
}
.custom-prep-measure-status {
  font-size: 11px;
  color: #4c6280;
  font-style: italic;
}
.custom-prep-measure input {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 2px 4px;
  border: 1px solid #c4d8e2;
  border-radius: 4px;
  color: #002f45;
  font-size: 13px;
}
.custom-prep-notes {
  min-height: 52px;
  white-space: pre-wrap;
}
.custom-prep-screen {
  display: none;
}
.custom-prep-screen:target {
  display: block;
}
body:has(.custom-prep-screen:target) .custom-prep-screen:target {
  display: block;
}

.custom-items-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.custom-items-table th,
.custom-items-table td {
  font-size: 13px;
}

.custom-items-table .supplier-po-col-row {
  width: 28px;
  max-width: 28px;
}

.custom-items-table .custom-pair-item-cell {
  width: auto;
  min-width: 0;
}

.custom-items-table .supplier-po-col-qty {
  width: 36px;
  max-width: 36px;
  text-align: center;
}

.custom-items-table .supplier-po-col-total {
  width: 50px;
  max-width: 50px;
  text-align: center;
}

.custom-items-table .supplier-po-delete-cell {
  width: 24px;
  max-width: 24px;
}

.custom-items-table .supplier-po-delete-row {
  min-width: 20px;
  min-height: 18px;
  padding: 0 3px;
  line-height: 1;
}

.custom-items-table .supplier-control {
  width: 100%;
  min-height: 24px;
  box-sizing: border-box;
  text-align: center;
}

.custom-items-table .ts-wrapper {
  width: 100%;
  min-width: 0;
}

.custom-items-table .ts-control {
  min-height: 26px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  background: transparent;
  box-shadow: none;
}

.custom-items-table .ts-control:focus-within {
  border-color: #8ba9df;
  background: #fff;
}

.custom-items-table .ts-dropdown {
  z-index: 9999;
  min-width: 320px;
}

.custom-items-table th:nth-child(1),
.custom-items-table td:nth-child(1) {
  width: 30px !important;
  max-width: 30px !important;
  text-align: center;
}

.custom-items-table th:nth-child(2),
.custom-items-table td:nth-child(2) {
  width: 40% !important;
  min-width: 0;
}

.custom-items-table th:nth-child(3),
.custom-items-table td:nth-child(3) {
  width: 58px !important;
  max-width: 58px !important;
  text-align: center;
}

.custom-items-table th:nth-child(4),
.custom-items-table td:nth-child(4) {
  width: 72px !important;
  max-width: 72px !important;
  text-align: center;
}

.custom-items-table th:nth-child(5),
.custom-items-table td:nth-child(5) {
  width: 72px !important;
  max-width: 72px !important;
  text-align: center;
}

.custom-items-table th:nth-child(6),
.custom-items-table td:nth-child(6) {
  width: 26px !important;
  max-width: 26px !important;
  text-align: center;
}


#custom-order-host {
  display: contents;
}

#custom-orders.custom-order-active-fallback,
#custom-order.custom-order-active-fallback,
#custom-order-preparation.custom-order-active-fallback {
  display: block;
}

body:has(#custom-orders.custom-order-active-fallback) .dashboard,
body:has(#custom-order.custom-order-active-fallback) .dashboard,
body:has(#custom-order-preparation.custom-order-active-fallback) .dashboard {
  display: none;
}

/* Route-entry loading state (set by CustomOrderLifecycle): a Custom Order screen
   paints once with its content hidden and a spinner, then reveals the rendered
   data, instead of showing stale content -> full-page loader -> new content. */
body:not(.mobile-shell-active) #custom-order-host .screen.co-route-loading {
  position: relative;
  min-height: 240px;
}

body:not(.mobile-shell-active) #custom-order-host .screen.co-route-loading > * {
  visibility: hidden;
}

/* Same AH needle-stitch animation as the full-page #loader, as a standalone SVG
   (a pseudo-element cannot hold inline SVG). 520x352 viewBox -> 150px x 101.5px. */
body:not(.mobile-shell-active) #custom-order-host .screen.co-route-loading::after {
  content: "";
  position: absolute;
  top: 120px;
  left: 50%;
  width: 150px;
  height: calc(150px * 352 / 520);
  margin-left: -75px;
  background: url("../../assets/ah-loader.svg?v=1") center / contain no-repeat;
}
