.sailing-ledger-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 20px 0 14px;
}
.sailing-ledger-heading h2 {
  font-size: 20px;
  margin: 0;
}
.sailing-ledger-heading > span,
.sailing-ledger-footnote {
  font-size: 13px;
  color: #718096;
}
.sailing-ledger-port {
  border: 1px solid #dce5eb;
  border-radius: 12px;
  overflow: hidden;
  margin: 0 0 22px;
  background: #fff;
}
.sailing-ledger-port h3 {
  margin: 0;
  padding: 13px 18px;
  background: #22736c;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 18px;
}
.sailing-ledger-port h3 span {
  font-weight: 400;
  font-size: 13px;
  color: #e6f1ef;
}
.sailing-ledger-scroll {
  overflow: auto;
  max-width: 100%;
  scrollbar-width: auto;
  overscroll-behavior-x: contain;
}
.sailing-ledger-scroll table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1770px;
  width: 100%;
  table-layout: auto;
  font-size: 13px;
}
.sailing-ledger-scroll th {
  background: #faf0f1;
  color: #485464;
  font-size: 12px;
  white-space: nowrap;
  padding: 12px 10px;
  text-align: center;
  border-bottom: 1px solid #e5dfe2;
}
.sailing-ledger-scroll th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
}
.sailing-ledger-scroll td {
  padding: 7px 9px;
  border-bottom: 1px solid #e7edf0;
  border-right: 1px solid #edf1f4;
  vertical-align: middle;
  text-align: center;
  white-space: nowrap;
  line-height: 1.35;
}
.sailing-ledger-scroll tbody tr:last-child td {
  border-bottom: 0;
}
.sailing-ledger-scroll .ledger-identity {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
  text-align: left;
  min-width: 170px;
  border-right: 1px solid #dde5e9;
}
.sailing-ledger-scroll .ledger-identity small {
  display: block;
  color: #84909e;
  font-size: 11px;
  margin-top: 3px;
}
.sailing-ledger-scroll .ledger-latest {
  background: #fff8df;
  font-weight: 600;
  color: #66521d;
}
.sailing-ledger-scroll .ledger-vessel {
  min-width: 150px;
  max-width: 240px;
  white-space: normal;
  text-align: left;
}
.sailing-ledger-scroll .ledger-vessel > span,
.sailing-ledger-scroll .ledger-vessel > strong {
  display: block;
  overflow-wrap: anywhere;
  margin-bottom: 2px;
}
.sailing-ledger-scroll .ledger-vessel .text-button { font-size: 11px; line-height: 1.35; padding: 0; }
.sailing-ledger-scroll .ledger-delays {
  min-width: 110px;
  text-align: center;
  white-space: normal;
  font-size: 11px;
}
.ledger-delays > div {
  border-left: 2px solid #d6b36d;
  padding-left: 7px;
  margin-bottom: 8px;
}
.ledger-delays > div > span {
  display: block;
  white-space: nowrap;
  line-height: 1.7;
}
.sailing-ledger-scroll .ledger-notes {
  min-width: 170px;
  max-width: 240px;
  text-align: left;
  white-space: normal;
}
.ledger-notes textarea {
  min-width: 150px;
  max-width: 100%;
  font-size: 12px;
}
.sailing-ledger-filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.sailing-ledger-filters select {
  width: auto;
  min-width: 150px;
  max-width: 280px;
  flex: 1;
}
.sailing-tool.sailing-booked .sailing-topbar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
}
.sailing-topbar > .sailing-intake {
  order: -1;
  width: 100%;
}
.sailing-ledger-secondary {
  margin-top: 20px;
}
.sailing-ledger-secondary > summary {
  cursor: pointer;
  color: #53746e;
  font-size: 13px;
  padding: 12px 0;
}
.sailing-ledger-delay-detail {
  border: 1px solid #e1e8ec;
  border-radius: 8px;
  padding: 15px;
  margin: 12px 0;
}
.sailing-ledger-delay-detail small {
  display: block;
  color: #718096;
  margin-top: 4px;
}
.sailing-ledger-delay-detail p {
  font-size: 13px;
  margin: 8px 0;
}
.sailing-ledger-delay-detail a {
  font-size: 12px;
}
@media (max-width: 600px) {
  .sailing-ledger-heading h2 {
    font-size: 18px;
  }
  .sailing-ledger-filters select {
    flex: 1;
    min-width: 120px;
  }
  .sailing-ledger-scroll .ledger-identity {
    min-width: 145px;
  }
  .sailing-ledger-port h3 {
    padding: 12px;
    font-size: 16px;
  }
}
.sailing-booking-target { display: grid; gap: 5px; color: var(--sailing-green); font-size: 12px; }
.sailing-booking-target select { width: 100%; min-width: 0; padding: 8px 10px; background: white; border: 1px solid var(--sailing-border); border-radius: 8px; }
.sailing-booking-target small { color: var(--muted); }
.sailing-ledger-scroll .ledger-date-edit { display: block; margin: 4px auto 0; font-size: 11px; line-height: 14px; font-weight: 400; padding: 0; }
.ledger-original > span { display: block; }
.sailing-delay-popover { position: fixed; z-index: 1200; width: 360px; max-width: calc(100vw - 16px); max-height: min(320px, calc(100vh - 40px)); overflow: auto; padding: 14px 16px; border: 1px solid #dce5eb; border-radius: 10px; background: white; box-shadow: 0 8px 30px #213b4929; color: #344555; font-size: 12px; }
.sailing-delay-popover > strong { display: block; font-size: 13px; margin-bottom: 10px; }
.sailing-popover-delay { border-top: 1px solid #e7edf0; padding: 10px 0; }
.sailing-popover-delay b, .sailing-popover-delay small, .sailing-popover-delay span { display: block; line-height: 1.7; }
.sailing-popover-delay small { color: #718096; margin-bottom: 4px; }
.sailing-date-revision { padding: 8px 0; }
.sailing-date-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 22px 0; }
.sailing-date-fields input { width: 100%; min-width: 0; }
.sailing-date-fields.sailing-single-date { grid-template-columns: minmax(0, 1fr); }
.sailing-date-actions { display: flex; justify-content: flex-end; gap: 10px; }
.sailing-eta-undetermined { display: flex; align-items: center; gap: 8px; margin: -6px 0 24px; font-size: 14px; cursor: pointer; }
.sailing-eta-undetermined input { width: auto; flex: 0 0 auto; }
@media (max-width: 460px) { .sailing-date-fields { grid-template-columns: 1fr; gap: 12px; } }
.modal.wide.sailing-past-modal { width: min(1880px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 20px; }
.sailing-past-modal > .modal-head { position: sticky; top: -20px; z-index: 3; background: white; padding: 10px 0; margin-bottom: 8px; }
.sailing-past-description { color: #718096; font-size: 13px; margin: 0 0 16px; }
.sailing-past-modal .sailing-past-search { display: flex; width: 100%; max-width: none; margin-bottom: 16px; }
.sailing-past-content .sailing-ledger-heading { margin-top: 16px; }
@media (max-width: 600px) {
  .modal.wide.sailing-past-modal { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); padding: 12px; }
  .sailing-past-modal > .modal-head { top: -12px; flex-wrap: wrap; gap: 8px; }
  .sailing-past-modal .modal-head h2 { font-size: 18px; }
}

.factory-page {
  min-width: 0;
}
.page-head.factory-page-head {
  display: grid;
  grid-template-columns: minmax(280px, 440px) minmax(240px, 480px) auto;
  align-items: start;
  justify-content: normal;
}
.factory-heading-copy {
  min-width: 0;
}
.factory-page-head > .row-actions {
  justify-content: flex-end;
  margin-left: auto;
  white-space: nowrap;
}
.factory-global-search {
  display: flex;
  align-items: center;
  position: relative;
  margin-top: 6px;
  min-width: 0;
  max-width: 100%;
}
.factory-global-search > svg {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}
.factory-global-search input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding-left: 38px;
  padding-right: 36px;
}
.factory-global-search button {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 7px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}
.factory-global-search button:hover {
  background: #edf3f0;
  color: var(--green);
}
.factory-search-scope {
  color: var(--green);
  font-size: 13px;
}
.factory-result-factory {
  color: var(--green);
  font-weight: 600;
}
.factory-manual-entry {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  margin: 14px 0;
  border: 1px solid #bcdace;
  border-radius: 7px;
  background: #f1f8f4;
}
.factory-manual-entry h4,
.factory-manual-entry p {
  margin: 0;
}
.factory-manual-entry p,
.factory-manual-entry > small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.factory-manual-entry > label:not(.factory-identity-check) {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}
.factory-manual-entry input:not([type="checkbox"]) {
  width: 100%;
  min-width: 0;
}
.factory-manual-draft-notice {
  padding: 10px 12px;
  margin: 12px 0;
  border-radius: 5px;
  background: #eaf5ef;
  color: var(--green);
  font-size: 12px;
  line-height: 1.6;
}
@media (max-width: 1050px) {
  .page-head.factory-page-head {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px 18px;
  }
  .factory-global-search {
    grid-column: 1 / -1;
    grid-row: 2;
    width: min(100%, 480px);
    margin-top: 0;
  }
}
@media (max-width: 520px) {
  .page-head.factory-page-head {
    grid-template-columns: minmax(0, 1fr);
  }
  .factory-page-head > .row-actions {
    grid-row: 2;
    margin-left: 0;
    justify-content: flex-start;
  }
  .factory-global-search {
    grid-row: 3;
  }
}
.factory-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 18px 0;
}
.factory-tabs button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 66px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  color: #324158;
}
.factory-tabs strong {
  font-size: 21px;
}
.factory-tabs span {
  font-size: 13px;
  color: var(--muted);
}
.factory-tabs button.selected {
  border-color: var(--green);
  background: #eaf4f0;
  color: var(--green);
}
.factory-grade-counts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.factory-grade-counts > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}
.factory-grade-counts .gold {
  color: #916910;
  background: #fff6d9;
}
.factory-grade-counts .red {
  color: #aa4545;
  background: #fff0ee;
}
.factory-grade-counts .blue {
  color: #3b6f9c;
  background: #edf5fe;
}
.factory-grade-counts .green {
  color: #347259;
  background: #eaf5ee;
}
.factory-loading-quantities > strong {
  display: block;
  margin-top: 8px;
  font-size: 12px;
}
.factory-quantity-cell {
  min-width: 340px;
}
.factory-quantity-cell .factory-grade-counts {
  grid-template-columns: repeat(2, 1fr);
}
.factory-grade-prices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 5px;
  align-items: start;
}
.factory-grade-price-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-radius: 4px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.factory-grade-price-group.gold {
  color: #916910;
  background: #fff6d9;
}
.factory-grade-price-group.red {
  color: #aa4545;
  background: #fff0ee;
}
.factory-grade-price-group.blue {
  color: #3b6f9c;
  background: #edf5fe;
}
.factory-grade-price-group.green {
  color: #347259;
  background: #eaf5ee;
}
.factory-grade-price-line {
  display: grid;
  grid-template-columns: minmax(36px, 0.8fr) minmax(38px, 0.85fr) minmax(
      76px,
      1.55fr
    );
  align-items: center;
  min-height: 18px;
  padding: 1px 5px;
  font-size: 11px;
  line-height: 16px;
  white-space: nowrap;
}
.factory-grade-price-line > span,
.factory-grade-price-line > b {
  text-align: right;
  font-weight: 600;
}
.factory-grade-price-line > :nth-child(n + 2) {
  border-left: 1px solid currentColor;
  margin-left: 4px;
  padding-left: 4px;
}
.factory-grade-amount {
  cursor: help;
}
.factory-grade-amount:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
  border-radius: 2px;
}
.factory-formula-tooltip {
  position: fixed;
  z-index: 1200;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  border: 1px solid #d8e2dc;
  border-radius: 7px;
  background: #fff;
  color: #324158;
  box-shadow: 0 6px 22px #1c342526;
  pointer-events: none;
  font-size: 12px;
  line-height: 1.7;
}
.factory-formula-tooltip > strong {
  display: block;
  margin-bottom: 4px;
  color: var(--green);
  font-size: 12px;
}
.factory-formula-tooltip > div {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.factory-formula-tooltip b {
  color: var(--green);
}
.factory-table .factory-loading-prices > small {
  margin-top: 3px;
  line-height: 14px;
}
.factory-extra-costs {
  min-width: 150px;
}
.factory-extra-costs > div {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  padding: 2px 0;
  white-space: nowrap;
}
.factory-extra-costs > div > span {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}
.factory-extra-costs b {
  flex-shrink: 0;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.factory-cost-summary {
  min-width: 125px;
}
.factory-editor-loading {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 24px;
  background: #f8fafb;
  border-radius: 6px;
  padding: 12px;
}
.factory-editor-loading > span {
  font-size: 12px;
  color: var(--muted);
}
.factory-editor-loading .factory-loading-quantities {
  flex: 1;
}
.factory-filters {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 20px 0;
}
.factory-filters label {
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}
.factory-filters label select {
  width: 160px;
}
.factory-filters > span {
  margin-left: auto;
}
.factory-unassigned {
  display: flex;
  gap: 15px;
  align-items: center;
  padding: 12px 16px;
  background: #fff8e9;
  border-radius: 6px;
}
.factory-list {
  overflow: hidden;
}
.factory-table-scroll {
  overflow: auto;
  container-type: inline-size;
}
.factory-table {
  width: 100%;
  min-width: 1510px;
  table-layout: fixed;
  border-collapse: collapse;
}
.factory-col-invoice {
  width: 150px;
}
.factory-col-vo {
  width: 124px;
}
.factory-col-container {
  width: 126px;
}
.factory-col-mark {
  width: 82px;
}
.factory-col-quantities {
  width: 360px;
}
.factory-col-goods {
  width: 150px;
}
.factory-col-fees {
  width: 170px;
}
.factory-col-total {
  width: 200px;
}
.factory-col-status {
  width: 108px;
}
.factory-col-action {
  width: 108px;
}
.factory-table > thead th {
  background: #f7f9fb;
  padding: 9px 8px;
  text-align: left;
  color: #4a596e;
  font-size: 12px;
  white-space: nowrap;
}
.factory-table > tbody > tr > td {
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  vertical-align: middle;
}
.factory-table > tbody > tr.selected > td {
  background: #edf6f2;
}
.factory-table > thead th:first-child,
.factory-table > tbody > tr > td:first-child {
  padding-left: 10px;
}
.factory-table > tbody > tr:not(.factory-editor-row) > td:nth-child(-n + 4) {
  white-space: nowrap;
}
.factory-table
  > tbody
  > tr:not(.factory-editor-row)
  > td:nth-child(n + 7):nth-child(-n + 8)
  > div,
.factory-table .factory-price > strong {
  white-space: nowrap;
}
.factory-table > tbody > tr > td small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}
.factory-table .mono {
  white-space: nowrap;
}
.factory-invoice {
  color: var(--green);
  border: 0;
  background: none;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-weight: 600;
  text-align: left;
}
.factory-mark-chip {
  display: inline-block;
  padding: 4px 7px;
  background: #eef2f5;
  border-radius: 4px;
}
.factory-vessel {
  max-width: 155px;
}
.factory-price {
  min-width: 130px;
}
.factory-price strong {
  font-variant-numeric: tabular-nums;
}
.factory-table > thead th.factory-total-heading {
  background: #e3f0e8;
  color: #17604b;
  font-size: 13px;
  font-weight: 700;
}
.factory-table > tbody > tr > td.factory-price {
  background: #eef6f1;
  border-left: 1px solid #d9e9de;
  border-right: 1px solid #d9e9de;
}
.factory-table > tbody > tr.selected > td.factory-price {
  background: #e3f0e8;
}
.factory-table .factory-price > strong {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
  color: #20533e;
}
.factory-table .factory-price > strong.factory-total-placeholder {
  font-size: 13px;
  font-weight: 600;
  white-space: normal;
  color: var(--muted);
}
.factory-cost-entry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-bottom-width: 2px;
  border-radius: 5px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.factory-cost-entry.is-complete {
  background: #eef1f4;
  border-color: #dce2e8;
  color: #697587;
}
.factory-cost-entry.is-complete:hover {
  background: #e2e7ed;
}
.factory-cost-entry.is-pending {
  background: #f0f8f4;
  border-color: #278166;
  color: var(--green);
}
.factory-cost-entry.is-pending:hover {
  background: #e2f2e9;
}
.factory-table .text-button {
  white-space: nowrap;
  display: flex;
  font-size: 12px;
  padding: 3px 0;
}
.factory-table > tbody > .factory-editor-row > td,
.factory-table > tbody > .factory-editor-row > td:first-child {
  padding: 0;
  background: #f8fafb;
}
.factory-editor {
  padding: 22px;
  min-width: 0;
  width: 100cqw;
  max-width: 100%;
}
.factory-editor-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.factory-editor h3 {
  margin: 0 0 8px;
  font-size: 18px;
}
.factory-identifiers {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  color: var(--muted);
  font-size: 12px;
}
.factory-identifiers b {
  color: #324158;
  margin-left: 5px;
  font-weight: 500;
}
.factory-cost-state {
  border-radius: 5px;
  padding: 5px 12px;
  background: #e9edf2;
  white-space: nowrap;
}
.factory-cost-state-confirmed {
  color: var(--green);
  background: #e4f2eb;
}
.factory-cost-state-draft {
  color: #996814;
  background: #fff2d7;
}
.factory-cost-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 20px;
}
.factory-cost-main,
.factory-recognition {
  padding: 18px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  min-width: 0;
}
.factory-cost-context {
  display: flex;
  align-items: center;
  gap: 15px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.factory-label-preview {
  width: 66px;
  flex-shrink: 0;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px;
}
.factory-label-preview img {
  width: 54px;
  height: 40px;
  object-fit: contain;
  display: block;
}
.factory-label-preview strong {
  font-size: 12px;
}
.factory-cost-context > div:nth-child(2) {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.factory-cost-context small {
  color: var(--muted);
}
.factory-cost-context > label {
  margin-left: auto;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.factory-cost-context select {
  width: 130px;
}
.factory-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 0 10px;
}
.factory-section-head h4,
.factory-recognition h4 {
  margin: 0;
  font-size: 14px;
}
.factory-section-head .text-button {
  display: flex;
  font-size: 12px;
}
.factory-cost-table-scroll {
  overflow: auto;
}
.factory-cost-table,
.factory-fee-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
}
.factory-cost-table th,
.factory-fee-table th {
  background: #f3f6f8;
  color: #5c6b7f;
  text-align: left;
  padding: 9px 6px;
  font-weight: 500;
  font-size: 12px;
}
.factory-cost-table td,
.factory-fee-table td {
  border-bottom: 1px solid #e9edf2;
  padding: 8px 4px;
  vertical-align: top;
}
.factory-cost-table {
  min-width: 960px;
}
.factory-cost-table th:nth-child(1) {
  width: 140px;
}
.factory-cost-table th:nth-child(2) {
  width: 110px;
}
.factory-cost-table th:nth-child(3) {
  width: 80px;
}
.factory-cost-table th:nth-child(4) {
  width: 72px;
}
.factory-cost-table th:nth-child(5) {
  width: 88px;
}
.factory-cost-table th:nth-child(6),
.factory-cost-table th:nth-child(7) {
  width: 100px;
}
.factory-cost-table th:nth-child(8),
.factory-cost-table th:nth-child(9) {
  width: 108px;
}
.factory-cost-table th:last-child,
.factory-fee-table th:last-child {
  width: 32px;
}
.factory-cost-main input,
.factory-cost-main select {
  width: 100%;
  min-width: 0;
  font-size: 12px;
  padding: 7px 6px;
}
.factory-cost-table td > input,
.factory-cost-table td > select,
.factory-fee-table td > input,
.factory-fee-table td > select {
  height: 36px;
  min-height: 36px;
  margin-top: 0;
  vertical-align: top;
  box-sizing: border-box;
}
.factory-cost-table td > small,
.factory-fee-table td > small {
  display: block;
  margin-top: 4px;
  line-height: 16px;
}
.modal:has(.factory-review-body) {
  width: min(1200px, calc(100vw - 32px));
}
.modal:has(.factory-product-review) {
  width: min(1560px, calc(100vw - 32px));
}
.factory-product-review .factory-review-table {
  min-width: 920px;
}
.factory-product-review .factory-review-table td:nth-last-child(2) {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.factory-review-body {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 22px;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}
.factory-identity-review {
  grid-template-columns: minmax(220px, 1fr) minmax(280px, 1fr);
}
.factory-review-original {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
  color: var(--green);
}
.factory-review-original img {
  display: block;
  width: 100%;
  height: 360px;
  object-fit: contain;
  background: #f6f8f7;
}
.factory-identity-review form,
.factory-review-body label:not(.factory-review-check) {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.factory-review-body input:not([type="checkbox"]),
.factory-review-body select {
  width: 100%;
  min-width: 0;
  height: 36px;
}
.factory-review-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin: 18px 0;
}
.factory-review-check input {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.factory-review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.factory-review-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.factory-review-counts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 10px 0;
  font-size: 13px;
}
.factory-review-table-scroll {
  overflow-x: auto;
}
.factory-review-table {
  width: 100%;
  min-width: 650px;
  table-layout: fixed;
  border-collapse: collapse;
}
.factory-review-table td,
.factory-review-table th {
  padding: 7px 4px;
  vertical-align: top;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.factory-review-table input,
.factory-review-table select {
  padding: 7px 5px;
  font-size: 12px;
}
.factory-review-reason {
  margin-top: 14px;
  font-size: 13px;
}
@media (max-width: 720px) {
  .factory-review-body,
  .factory-identity-review {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  .factory-review-original img {
    height: 220px;
  }
  .factory-review-toolbar {
    flex-wrap: wrap;
  }
}
.factory-fee-table {
  min-width: 840px;
}
.factory-fee-table th:first-child {
  width: 130px;
}
.factory-fee-table th:nth-child(2) {
  width: 150px;
}
.factory-fee-table th:nth-child(3),
.factory-fee-table th:nth-child(4),
.factory-fee-table th:nth-child(5) {
  width: 100px;
}
.factory-fixed-currency {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}
.factory-third-price-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.factory-third-price-heading .text-button {
  font-size: 12px;
}
.factory-revision-summary {
  max-width: 420px;
  line-height: 1.5;
  color: var(--muted);
}
.factory-total-revision-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 18px 0;
}
.factory-total-revision-form input {
  height: 38px;
  width: 100%;
  min-width: 0;
}
.factory-revision-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-variant-numeric: tabular-nums;
}
.factory-revision-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}
.factory-total-revision-form small {
  color: var(--muted);
}
.factory-cost-table small,
.factory-fee-table small {
  font-size: 10px;
  color: var(--muted);
}
.factory-amount {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.factory-amount .factory-row-formula {
  display: block;
  white-space: normal;
  line-height: 1.4;
  margin-top: 4px;
}
.factory-line-empty {
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  text-align: center;
  padding: 22px 8px;
  font-size: 12px;
}
.factory-note {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 18px;
  font-size: 12px;
  color: #5c6b7f;
}
.factory-note textarea {
  min-height: 62px;
  font-size: 12px;
}
.factory-totals {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  align-items: center;
  margin-top: 18px;
  padding: 16px;
  background: #eef6f2;
  border-radius: 6px;
}
.factory-totals > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.factory-totals > span {
  color: #93a499;
}
.factory-totals div > span {
  font-size: 11px;
  color: #6a7b72;
}
.factory-totals strong {
  font-size: 14px;
}
.factory-third-price strong {
  color: var(--green);
  font-size: 20px;
}
.factory-save-row {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}
.factory-save-row small {
  margin-right: auto;
}
.factory-cost-history {
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
}
.factory-cost-history > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.factory-cost-history b {
  color: #475569;
  font-weight: 500;
}
.factory-recognition {
  align-self: start;
  white-space: normal;
  padding: 12px;
}
.factory-recognition h4 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}
.factory-ai-instructions,
.factory-ai-progress {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}
.factory-ai-progress {
  color: var(--green);
}
.factory-ai-target {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}
.factory-ai-target b {
  color: #324158;
  font-family: ui-monospace, SFMono-Regular, monospace;
  overflow-wrap: anywhere;
}
.factory-cabinet-validation {
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
}
.factory-cabinet-validation.matched {
  color: #27694e;
  background: #eaf5ee;
}
.factory-cabinet-validation.blocked {
  color: #a23e37;
  background: #fff0ee;
}
.factory-cabinet-validation > strong {
  display: block;
  margin-bottom: 4px;
}
.factory-cabinet-validation > div {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr);
  gap: 8px;
  margin: 4px 0;
}
.factory-cabinet-validation b {
  font-family: ui-monospace, SFMono-Regular, monospace;
  overflow-wrap: anywhere;
  font-weight: 500;
}
.factory-cabinet-validation p {
  margin: 6px 0 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.factory-cabinet-validation.corrected {
  color: #965d13;
  background: #fff7e7;
}
.factory-cabinet-validation > .btn {
  margin-top: 8px;
  padding: 6px 9px;
  width: 100%;
  font-size: 12px;
}
.factory-cabinet-validation > small {
  display: block;
  margin-top: 5px;
}
.factory-cabinet-validation > .factory-cabinet-entry {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.factory-cabinet-entry input {
  width: 100%;
  min-width: 0;
  font-size: 12px;
}
.factory-cabinet-entry .btn {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
}
.factory-recognition .upload-drop-area {
  padding: 8px;
  background: #f7faf8;
}
.factory-recognition .upload-drop-area > button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 5px 0;
}
.factory-recognition .upload-drop-area span {
  font-size: 11px;
  color: var(--muted);
}
.factory-recognition > select {
  width: 100%;
  margin-top: 8px;
  font-size: 12px;
  padding: 6px 8px;
}
.factory-original-preview {
  display: block;
  text-align: center;
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.factory-recognition .factory-original-preview img {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  display: block;
}
.factory-original-preview span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px;
  font-size: 12px;
  background: #f8fafb;
}
.factory-recognition .tiff-preview-compact label {
  padding: 5px 8px;
}
.factory-recognition .tiff-preview-compact select {
  padding: 4px 6px;
}
.factory-recognition .factory-original-preview > a {
  padding: 5px 8px;
}
.factory-recognition > .button,
.factory-recognition > .btn {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
}
.factory-recognition > .muted {
  display: block;
  margin-top: 8px;
}
.factory-ai-result {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.factory-ai-result > p {
  margin: 6px 0;
}
.factory-ai-result-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 8px;
  margin-bottom: 8px;
}
.factory-ai-result-head small {
  color: var(--muted);
}
.factory-recognized-identity div {
  display: flex;
  flex-direction: column;
  margin: 7px 0;
}
.factory-recognized-identity span {
  color: var(--muted);
}
.factory-recognized-identity b {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.factory-ai-lines {
  max-height: 160px;
  overflow: auto;
  background: #f7f9fb;
  padding: 6px 8px;
  border-radius: 4px;
}
.factory-ai-lines div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 6px 0;
}
.factory-ai-lines small {
  color: var(--muted);
}
.factory-recognized-totals {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0;
}
.factory-recognized-totals > strong {
  display: block;
  padding: 8px 10px;
  border-radius: 5px;
  background: #fff0ee;
  color: #b42318;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.factory-ai-lines b {
  font-weight: 500;
}
.factory-cost-warning {
  padding: 10px 12px;
  color: #965d13;
  background: #fff7e7;
  border-radius: 5px;
  font-size: 12px;
}
ul.factory-cost-warning {
  padding-left: 26px;
}
.factory-identity-check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 8px 0;
  line-height: 1.5;
}
.factory-identity-check input {
  margin-top: 4px;
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  padding: 0;
}
.factory-recognition details {
  margin-top: 8px;
  font-size: 12px;
  color: #5c6b7f;
}
.factory-recognition pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  max-height: 280px;
  overflow: auto;
  background: #f7f9fb;
  padding: 10px;
}
.factory-legacy-back {
  margin-bottom: 18px;
}
main.factory-main {
  max-width: none;
  width: 100%;
  padding: 26px 24px;
}
@media (max-width: 700px) {
  .factory-editor-loading {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .factory-editor-loading .factory-grade-counts {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 1100px) {
  .factory-cost-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
  .factory-editor {
    padding: 16px;
  }
}
@media (max-width: 700px) {
  main.factory-main {
    padding: 18px 12px;
  }
  .factory-tabs {
    gap: 6px;
  }
  .factory-tabs button {
    flex-direction: column;
    gap: 2px;
  }
  .factory-filters {
    flex-wrap: wrap;
    gap: 10px;
  }
  .factory-editor {
    width: calc(100vw - 42px);
    max-width: calc(100vw - 42px);
    padding: 12px;
  }
  .factory-editor-heading,
  .factory-cost-context,
  .factory-save-row {
    flex-wrap: wrap;
  }
  .factory-cost-context > label {
    margin-left: 0;
  }
  .factory-cost-layout {
    grid-template-columns: 1fr;
  }
  .factory-cost-table {
    min-width: 600px;
  }
  .factory-fee-table {
    min-width: 540px;
  }
  .factory-totals {
    flex-wrap: wrap;
  }
  .factory-cost-history > div {
    flex-direction: column;
  }
}

.factory-settlement-date {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
  font-size: 12px;
}
.factory-settlement-date input {
  width: 150px;
  min-height: 30px;
  padding: 5px 8px;
}
.factory-settlement-date small,
.factory-song-review > small {
  color: #8493a4;
}
.factory-quantity-review {
  font-size: 12px;
  margin: 8px 0;
  color: #197253;
}
.factory-quantity-review input {
  max-width: 460px;
  margin-top: 6px;
}
.factory-review-error {
  color: #a16318;
  background: #fff7e7;
  padding: 8px;
  border-radius: 4px;
}
.factory-song-review table {
  font-size: 10px;
  width: 100%;
  table-layout: fixed;
  overflow-wrap: anywhere;
  margin: 6px 0;
}
.factory-song-review th,
.factory-song-review td {
  padding: 4px 2px;
  text-align: right;
  vertical-align: top;
}
.factory-song-review th:first-child,
.factory-song-review td:first-child {
  text-align: left;
}
.factory-check-digit {
  display: block;
  color: #a16318;
}

.factory-source-total-review {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.factory-source-total-review label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.factory-source-total-review input {
  width: 170px;
  min-height: 30px;
}
.factory-source-total-review > input {
  width: 280px;
  max-width: 100%;
}
.factory-category-label {
  display: block;
  color: #668775;
  font-size: 10px;
  margin-top: 3px;
}
.factory-cost-table .factory-category-choice,
.factory-fee-table .factory-category-choice {
  width: 100%;
  min-height: 25px;
  margin-top: 4px;
  font-size: 11px;
  color: #906128;
  border-color: #e3c99f;
}
.factory-category-review {
  padding: 9px 12px;
  border: 1px solid #ecd8b8;
  border-radius: 6px;
  background: #fffaf0;
  color: #8c642f;
  font-size: 12px;
}
.factory-category-review summary {
  cursor: pointer;
  font-weight: 600;
}
.factory-category-review div,
.factory-category-review small {
  margin-top: 5px;
}

.factory-history-summary {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}
.factory-history-summary strong {
  color: var(--green);
  font-variant-numeric: tabular-nums;
}
.factory-history-quantity > span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.factory-history-quantity > small {
  color: var(--muted);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.6;
}
.factory-history-trend-note {
  margin: 16px 0 -4px;
  color: var(--green);
  font-size: 12px;
}
.factory-history-quote {
  white-space: pre-wrap;
}
@media (max-width: 520px) {
  .factory-history-summary {
    align-items: flex-start;
  }
}

.factory-ownership-confirmation { margin: 18px 0; padding: 16px; border: 1px solid #d7e6e0; border-radius: 8px; background: #f6faf8; }
.factory-ownership-confirmation h4 { margin: 0 0 8px; }
.factory-ownership-confirmation fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; max-width: 660px; }
.factory-ownership-confirmation label { display: grid; gap: 6px; }
.factory-ownership-confirmation select, .factory-ownership-confirmation textarea { width: 100%; min-width: 0; }
.factory-ownership-confirmation textarea { min-height: 78px; resize: vertical; }
.factory-ownership-confirmation .factory-ownership-check { display: flex; align-items: center; gap: 8px; }
.factory-ownership-check input { width: auto; }
.factory-ownership-confirmation .button-row { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 700px) { .factory-ownership-confirmation fieldset { max-width: calc(100vw - 90px); } }

/* Keep cost, sort and cross-factory search in one aligned toolbar. */
.page-head.factory-page-head {
  grid-template-columns: minmax(0, 1fr) auto;
}
.factory-filters > .factory-global-search {
  flex: 1 1 420px;
  width: auto;
  min-width: 180px;
  max-width: 480px;
  margin-top: 0;
}
@media (max-width: 1100px) {
  .factory-filters { flex-wrap: wrap; }
}
@media (max-width: 700px) {
  .factory-filters > .factory-global-search {
    flex-basis: 100%;
    max-width: none;
  }
}

@media (max-width: 520px) {
  .page-head.factory-page-head { grid-template-columns: minmax(0, 1fr); }
}

/* Compact factory header: keep all selectors and existing table behavior. */
.factory-page .cabinet-scope {display:flex;align-items:center;flex-wrap:wrap;gap:8px 14px;padding:8px 12px;margin-bottom:10px;}
.factory-page .cabinet-scope-main {flex:1 1 auto;gap:8px;}
.factory-page .cabinet-scope > details {margin:0;font-size:11px;}
.factory-page .cabinet-scope > details summary {white-space:nowrap;}
.factory-page .cabinet-scope > details[open] {flex-basis:100%;}
.factory-page .cabinet-scope > p {flex-basis:100%;}
.factory-page .page-head.factory-page-head {display:flex;align-items:center;justify-content:space-between;gap:10px;margin:0 0 10px;flex-wrap:wrap;}
.factory-page .factory-heading-copy {display:flex;align-items:center;gap:14px;flex-wrap:wrap;}
.factory-page .factory-heading-copy h1 {font-size:24px;line-height:1.3;margin:0;white-space:nowrap;}
.factory-page .factory-tabs {display:flex;gap:6px;margin:0;}
.factory-page .factory-tabs button {min-height:34px;padding:6px 16px;border-radius:5px;gap:4px;}
.factory-page .factory-tabs strong {font-size:14px;white-space:nowrap;}
.factory-page .factory-page-head .button {min-height:32px;padding:6px 12px;font-size:12px;}
.factory-page .factory-filters {display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin:0 0 10px;padding:0;}
.factory-page .factory-filters label {font-size:12px;gap:6px;}
.factory-page .factory-filters select,.factory-page .factory-global-search input {height:32px;min-height:32px;font-size:12px;}
.factory-page .factory-global-search {flex:1 1 250px;max-width:540px;grid-column:auto;grid-row:auto;margin:0;}
.factory-page .factory-unassigned {display:flex;align-items:center;gap:8px;margin:0 0 0 auto;padding:6px 12px;min-height:32px;border-radius:20px;font-size:12px;white-space:nowrap;}
.factory-page .factory-list > .panel-head {min-height:40px;padding:8px 14px;gap:10px;}
.factory-page .factory-list > .panel-head h2 {font-size:16px;margin:0;}
.factory-page .factory-history-summary {display:flex;flex-direction:row;align-items:center;flex-wrap:wrap;gap:6px 14px;font-size:11px;}
@media(max-width:640px){
 .factory-page .factory-heading-copy {gap:8px;}
 .factory-page .factory-tabs button {padding:6px 10px;}
 .factory-page .factory-page-head > .row-actions {margin-left:0;}
 .factory-page .factory-global-search {flex-basis:100%;max-width:none;}
 .factory-page .factory-unassigned {margin-left:0;}
}
