/*
 * Sales order visual refresh.
 * Kept as the final, isolated stylesheet so the redesign is reversible and
 * cannot alter document behaviour or any other ERP module.
 */

.app-shell #editor-view {
  --so-border: #a8bac7;
  --so-border-strong: #7892a5;
  --so-surface: #ffffff;
  --so-surface-muted: #f3f7fa;
  --so-text: #142f43;
  --so-muted: #526b7c;
  padding: 3px 6px 12px !important;
  color: var(--so-text);
}

/* One compact document command header. */
.app-shell #editor-view > .document-header {
  height: 31px !important;
  min-height: 31px !important;
  max-height: 31px !important;
  margin: 0 0 4px !important;
  padding: 2px 3px !important;
  border-bottom: 1px solid var(--so-border-strong) !important;
  background: #fff !important;
}
.app-shell #editor-view .document-title {
  min-width: 0;
  gap: 5px !important;
}
.app-shell #editor-view .document-title .eyebrow {
  display: none !important;
}
.app-shell #editor-view .document-title h1 {
  margin: 0 !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  color: var(--so-text) !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-shell #editor-view .document-title .icon-button {
  width: 25px !important;
  height: 25px !important;
  min-width: 25px !important;
  padding: 0 !important;
  border: 1px solid var(--so-border) !important;
  border-radius: 4px !important;
  font-size: 14px !important;
}
.app-shell #editor-view #document-status {
  padding: 3px 7px !important;
  font-size: 9px !important;
  line-height: 1 !important;
  white-space: nowrap;
}
.app-shell #editor-view .document-actions {
  display: flex !important;
  align-items: center !important;
  gap: 3px !important;
  margin-inline-start: auto;
}
.app-shell #editor-view .document-actions .button {
  height: 25px !important;
  min-height: 25px !important;
  padding: 0 9px !important;
  border-radius: 4px !important;
  font-size: 10px !important;
}
.app-shell #editor-view > .form-message {
  margin: 0 0 4px !important;
  padding: 5px 8px !important;
  border-radius: 4px !important;
  font-size: 10px !important;
}

/* Dense layout with a narrow, useful summary column. */
.app-shell #editor-view .editor-layout {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 205px !important;
  gap: 5px !important;
  align-items: start !important;
}
.app-shell #editor-view .editor-main,
.app-shell #editor-view .editor-side {
  gap: 5px !important;
  min-width: 0 !important;
}
.app-shell #editor-view .content-card {
  border: 1px solid var(--so-border) !important;
  border-radius: 5px !important;
  background: var(--so-surface) !important;
  box-shadow: none !important;
}
.app-shell #editor-view :where(.form-card, .lines-card, .summary-card, .timeline-card) {
  padding: 5px 6px !important;
}
.app-shell #editor-view .section-title {
  min-height: 25px !important;
  margin: 0 0 4px !important;
  gap: 5px !important;
  border-bottom: 1px solid #d7e0e6;
}
.app-shell #editor-view .section-title .section-icon {
  display: none !important;
}
.app-shell #editor-view .section-title h2,
.app-shell #editor-view .summary-heading h2,
.app-shell #editor-view .timeline-card > h2 {
  margin: 0 !important;
  font-size: 12px !important;
  font-weight: 900 !important;
  line-height: 1.15 !important;
  color: var(--so-text) !important;
}
.app-shell #editor-view .section-title p {
  display: none !important;
}

/* Identity fields: explicit tracks stop labels and controls from colliding. */
.app-shell #editor-view .order-head-grid {
  display: grid !important;
  grid-template-columns:
    minmax(120px, .8fr)
    minmax(225px, 1.5fr)
    84px
    minmax(150px, 1fr)
    112px
    126px
    minmax(130px, .9fr) !important;
  gap: 4px 5px !important;
  align-items: end !important;
}
.app-shell #editor-view .order-head-grid > :where(.field, .order-creator-field) {
  min-width: 0 !important;
  margin: 0 !important;
}
.app-shell #editor-view .order-head-grid .field {
  display: grid !important;
  grid-template-rows: 14px 28px !important;
  gap: 1px !important;
}
.app-shell #editor-view .order-head-grid .field > span,
.app-shell #editor-view .order-creator-field > span {
  display: block !important;
  min-height: 0 !important;
  margin: 0 !important;
  font-size: 9px !important;
  font-weight: 900 !important;
  line-height: 14px !important;
  color: #263f52 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.app-shell #editor-view .order-head-grid :where(input, select, .smart-select-trigger, .smart-select-input) {
  width: 100% !important;
  height: 28px !important;
  min-height: 28px !important;
  min-width: 0 !important;
  padding: 3px 6px !important;
  border: 1px solid var(--so-border) !important;
  border-radius: 4px !important;
  background: #fff !important;
  font-size: 10px !important;
  font-weight: 650 !important;
  color: var(--so-text) !important;
}
.app-shell #editor-view .order-head-grid :where(input, select, .smart-select-input):focus {
  border-color: #2f75aa !important;
  box-shadow: 0 0 0 2px rgba(27, 101, 158, .1) !important;
}
.app-shell #editor-view .order-head-grid small {
  display: none !important;
}
.app-shell #editor-view .order-manual-code-field input {
  direction: ltr !important;
  text-align: center !important;
  font-family: Consolas, "Courier New", monospace !important;
}
.app-shell #editor-view .order-creator-field {
  display: grid !important;
  grid-template-rows: 14px 28px !important;
  gap: 1px !important;
  height: auto !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
}
.app-shell #editor-view .order-creator-field > strong {
  display: flex !important;
  align-items: center !important;
  min-width: 0 !important;
  height: 28px !important;
  padding: 3px 6px !important;
  border: 1px solid var(--so-border) !important;
  border-radius: 4px !important;
  background: var(--so-surface-muted) !important;
  font-size: 10px !important;
  color: var(--so-text) !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.app-shell #editor-view .order-creator-field > small {
  display: none !important;
}

/* Clear, fixed sales-line matrix on normal desktop widths. */
.app-shell #editor-view .lines-card {
  overflow: hidden !important;
}
.app-shell #editor-view .lines-title {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
}
.app-shell #editor-view .lines-heading-actions {
  display: flex !important;
  align-items: center !important;
  gap: 4px !important;
  margin-inline-start: auto !important;
}
.app-shell #editor-view #lines-quick-summary {
  padding: 2px 6px !important;
  border: 1px solid #d6e0e7;
  border-radius: 10px;
  background: var(--so-surface-muted);
  font-size: 8px !important;
  font-weight: 800;
  color: var(--so-muted);
  white-space: nowrap;
}
.app-shell #editor-view #add-line-btn {
  height: 23px !important;
  min-height: 23px !important;
  padding: 0 7px !important;
  border-color: #8eadc2 !important;
  border-radius: 4px !important;
  background: #edf5fb !important;
  color: #155f91 !important;
  font-size: 9px !important;
}
.app-shell #editor-view .lines-table-wrap {
  width: 100% !important;
  max-width: 100% !important;
  max-height: 430px !important;
  margin: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  border: 1px solid var(--so-border) !important;
  border-radius: 4px !important;
}
.app-shell #editor-view .professional-lines-table {
  width: 100% !important;
  min-width: 0 !important;
  table-layout: fixed !important;
  border-collapse: separate !important;
  border-spacing: 0 !important;
}
.app-shell #editor-view .professional-lines-table thead {
  position: sticky !important;
  top: 0 !important;
  z-index: 4 !important;
}
.app-shell #editor-view .professional-lines-table th {
  height: 24px !important;
  padding: 3px 2px !important;
  border-bottom: 1px solid var(--so-border-strong) !important;
  background: #eaf1f5 !important;
  font-size: 8.5px !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  color: #244257 !important;
  text-align: center !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.app-shell #editor-view .professional-lines-table th:nth-child(1) { width: 27px !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(2) { width: 24% !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(3) { width: 7% !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(4) { width: 9% !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(5),
.app-shell #editor-view .professional-lines-table th:nth-child(6),
.app-shell #editor-view .professional-lines-table th:nth-child(7) { width: 7% !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(8) { width: 8% !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(9) { width: 9% !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(10) { width: 10% !important; }
.app-shell #editor-view .professional-lines-table th:nth-child(11) { width: 52px !important; }
.app-shell #editor-view .line-main-row td {
  height: 36px !important;
  min-width: 0 !important;
  padding: 3px !important;
  border: 0 !important;
  border-bottom: 1px solid var(--so-border) !important;
  background: #fff !important;
  vertical-align: middle !important;
  overflow: hidden !important;
}
.app-shell #editor-view .line-main-row:nth-child(even) td {
  background: #fbfdfe !important;
}
.app-shell #editor-view .line-main-row:hover td {
  background: #f2f8fc !important;
}

.app-shell #editor-view .line-main-row.locked-order-line td {
  background: #f3f6f9 !important;
  color: #52677b;
}
.app-shell #editor-view .line-main-row.locked-order-line :where(input, select, .smart-select-trigger) {
  background: #eef2f6 !important;
  color: #52677b !important;
  cursor: not-allowed;
  opacity: 1;
}
.app-shell #editor-view .locked-line-label,
.app-shell .post-cycle-badge {
  display: block;
  margin-top: 2px;
  color: #0f766e;
  font-size: 9px;
  font-weight: 800;
  white-space: nowrap;
}
.app-shell #editor-view .post-cycle-addition-mode .order-head-grid {
  border-inline-start: 3px solid #0f766e;
}
.app-shell .post-cycle-line td {
  background: #f0fdfa;
}
.app-shell #editor-view .line-main-row :where(.line-input, .smart-select-trigger, .smart-select-input) {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  height: 28px !important;
  min-height: 28px !important;
  padding: 3px 5px !important;
  border: 1px solid #aabcc8 !important;
  border-radius: 4px !important;
  background: #fff !important;
  font-size: 9.5px !important;
  font-weight: 700 !important;
  line-height: 1.15 !important;
  color: var(--so-text) !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.app-shell #editor-view .line-main-row :where(.line-input, .smart-select-input):focus {
  border-color: #2f75aa !important;
  box-shadow: 0 0 0 2px rgba(27, 101, 158, .1) !important;
  outline: 0 !important;
}
.app-shell #editor-view .line-main-row td:nth-child(4) :where(.smart-select-input, .smart-select-trigger) {
  padding-inline: 20px 3px !important;
}
.app-shell #editor-view .measure-input-cell .line-input,
.app-shell #editor-view .quantity-input,
.app-shell #editor-view .density-input {
  text-align: center !important;
  font-variant-numeric: tabular-nums;
}
.app-shell #editor-view .quantity-with-unit {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 0 !important;
}
.app-shell #editor-view .quantity-with-unit small {
  display: none !important;
}
.app-shell #editor-view .line-sequence {
  display: grid !important;
  place-items: center !important;
  width: 20px !important;
  height: 20px !important;
  margin: auto !important;
  border-radius: 4px !important;
  background: #153f5e !important;
  color: #fff !important;
  font-size: 9px !important;
  font-weight: 900 !important;
}
.app-shell #editor-view .line-measure-cell strong {
  display: block !important;
  font-size: 9.5px !important;
  font-weight: 900 !important;
  color: #105f46 !important;
  text-align: center !important;
  white-space: nowrap !important;
}
.app-shell #editor-view .line-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 2px !important;
  flex-wrap: nowrap !important;
}
.app-shell #editor-view .line-action {
  width: 22px !important;
  min-width: 22px !important;
  height: 22px !important;
  padding: 0 !important;
  border: 1px solid #aebfca !important;
  border-radius: 4px !important;
  background: #fff !important;
  font-size: 11px !important;
}
.app-shell #editor-view .line-action.remove {
  border-color: #e1b9bd !important;
  background: #fff5f5 !important;
  color: #a22f3c !important;
}
.app-shell #editor-view .add-line-wide {
  height: 24px !important;
  margin: 4px 0 0 !important;
  padding: 0 7px !important;
  border: 1px dashed #8eabc0 !important;
  border-radius: 4px !important;
  background: #f7fafc !important;
  font-size: 9px !important;
  font-weight: 850 !important;
}

/* Notes and side information stay useful without consuming the page. */
.app-shell #editor-view .order-notes-card .section-title {
  min-height: 20px !important;
  margin-bottom: 3px !important;
}
.app-shell #editor-view .order-notes-card textarea {
  width: 100% !important;
  height: 34px !important;
  min-height: 34px !important;
  padding: 5px 7px !important;
  border: 1px solid var(--so-border) !important;
  border-radius: 4px !important;
  font-size: 10px !important;
  color: var(--so-text) !important;
  resize: vertical !important;
}
.app-shell #editor-view .summary-heading {
  min-height: 23px !important;
  margin: 0 0 2px !important;
  border-bottom: 1px solid #d7e0e6;
}
.app-shell #editor-view .summary-heading span {
  padding: 2px 5px !important;
  font-size: 8px !important;
}
.app-shell #editor-view .summary-row {
  min-height: 24px !important;
  padding: 4px 1px !important;
  border-bottom: 1px solid #e4eaee;
  font-size: 9px !important;
  color: var(--so-muted) !important;
}
.app-shell #editor-view .summary-row strong {
  font-size: 10px !important;
  color: var(--so-text) !important;
}
.app-shell #editor-view .summary-total {
  min-height: 26px !important;
  margin: 0 !important;
  padding: 5px 1px 0 !important;
  font-size: 9px !important;
}
.app-shell #editor-view .summary-total strong {
  font-size: 12px !important;
}
.app-shell #editor-view .timeline-card > h2 {
  min-height: 22px !important;
  margin-bottom: 2px !important;
  border-bottom: 1px solid #d7e0e6;
}
.app-shell #editor-view .timeline-item {
  min-height: 32px !important;
  padding: 3px 0 !important;
  gap: 5px !important;
}
.app-shell #editor-view .timeline-item i {
  width: 8px !important;
  height: 8px !important;
  margin-top: 2px !important;
}
.app-shell #editor-view .timeline-item strong {
  font-size: 9px !important;
  line-height: 1.1 !important;
  color: var(--so-text) !important;
}
.app-shell #editor-view .timeline-item span {
  margin-top: 2px !important;
  font-size: 8px !important;
  line-height: 1.1 !important;
  color: var(--so-muted) !important;
}
.app-shell #editor-view .timeline-item:not(:last-child)::after {
  top: 14px !important;
  height: 22px !important;
}

/*
 * Narrow desktop / remote browser: lines become a labelled two-row card.
 * This avoids horizontal scrolling and prevents any field from entering its
 * neighbour when the sidebar leaves less room for the document.
 */
@media (max-width: 1180px) {
  .app-shell #editor-view .editor-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .app-shell #editor-view .editor-side {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .app-shell #editor-view .order-head-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  }
  .app-shell #editor-view .order-agent-field { grid-column: span 2 !important; }
  .app-shell #editor-view .order-customer-field { grid-column: span 4 !important; }
  .app-shell #editor-view .order-manual-code-field { grid-column: span 1 !important; }
  .app-shell #editor-view .order-manual-name-field { grid-column: span 2 !important; }
  .app-shell #editor-view .order-date-field,
  .app-shell #editor-view .order-delivery-date-field,
  .app-shell #editor-view .order-creator-field { grid-column: span 1 !important; }

  .app-shell #editor-view .lines-table-wrap {
    max-height: none !important;
    overflow: visible !important;
    border: 0 !important;
  }
  .app-shell #editor-view .professional-lines-table,
  .app-shell #editor-view .professional-lines-table tbody {
    display: block !important;
    width: 100% !important;
  }
  .app-shell #editor-view .professional-lines-table thead {
    display: none !important;
  }
  .app-shell #editor-view .professional-lines-table tbody {
    display: grid !important;
    gap: 5px !important;
  }
  .app-shell #editor-view .line-main-row {
    display: grid !important;
    grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
    gap: 4px !important;
    padding: 5px !important;
    border: 1px solid var(--so-border) !important;
    border-right: 3px solid #236f9f !important;
    border-radius: 5px !important;
    background: #fff !important;
  }
  .app-shell #editor-view .line-main-row td {
    display: grid !important;
    grid-template-rows: 13px 28px !important;
    gap: 1px !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    overflow: visible !important;
  }
  .app-shell #editor-view .line-main-row td::before {
    display: block;
    font-size: 8px;
    font-weight: 900;
    line-height: 13px;
    color: #3d586a;
    white-space: nowrap;
  }
  .app-shell #editor-view .line-main-row td:nth-child(1) { grid-column: span 1; grid-row: 1; }
  .app-shell #editor-view .line-main-row td:nth-child(2) { grid-column: span 7; grid-row: 1; }
  .app-shell #editor-view .line-main-row td:nth-child(3) { grid-column: span 2; grid-row: 1; }
  .app-shell #editor-view .line-main-row td:nth-child(4) { grid-column: span 2; grid-row: 1; }
  .app-shell #editor-view .line-main-row td:nth-child(5),
  .app-shell #editor-view .line-main-row td:nth-child(6),
  .app-shell #editor-view .line-main-row td:nth-child(7),
  .app-shell #editor-view .line-main-row td:nth-child(8),
  .app-shell #editor-view .line-main-row td:nth-child(9),
  .app-shell #editor-view .line-main-row td:nth-child(10) { grid-column: span 2; grid-row: 2; }
  .app-shell #editor-view .line-main-row td:nth-child(11) {
    grid-column: 11 / 13;
    grid-row: 3;
    grid-template-rows: 13px 24px !important;
  }
  .app-shell #editor-view .line-main-row td:nth-child(1)::before { content: "#"; }
  .app-shell #editor-view .line-main-row td:nth-child(2)::before { content: "الصنف"; }
  .app-shell #editor-view .line-main-row td:nth-child(3)::before { content: "العدد"; }
  .app-shell #editor-view .line-main-row td:nth-child(4)::before { content: "الوحدة"; }
  .app-shell #editor-view .line-main-row td:nth-child(5)::before { content: "الطول (سم)"; }
  .app-shell #editor-view .line-main-row td:nth-child(6)::before { content: "العرض (سم)"; }
  .app-shell #editor-view .line-main-row td:nth-child(7)::before { content: "السمك (مم)"; }
  .app-shell #editor-view .line-main-row td:nth-child(8)::before { content: "الكثافة"; }
  .app-shell #editor-view .line-main-row td:nth-child(9)::before { content: "اللون"; }
  .app-shell #editor-view .line-main-row td:nth-child(10)::before { content: "إجمالي البند"; }
  .app-shell #editor-view .line-main-row td:nth-child(11)::before { content: "إجراءات"; }
  .app-shell #editor-view .line-main-row td:nth-child(1) .line-sequence {
    margin: 4px auto 0 !important;
  }
}

@media (max-width: 760px) {
  .app-shell #editor-view {
    padding-inline: 4px !important;
  }
  .app-shell #editor-view > .document-header {
    height: auto !important;
    min-height: 31px !important;
    max-height: none !important;
    flex-wrap: wrap !important;
  }
  .app-shell #editor-view .document-title {
    flex: 1 1 auto;
  }
  .app-shell #editor-view .document-actions {
    flex: 0 0 auto;
    flex-direction: row !important;
  }
  .app-shell #editor-view .order-head-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .app-shell #editor-view :where(.order-agent-field, .order-customer-field) {
    grid-column: 1 / -1 !important;
  }
  .app-shell #editor-view :where(.order-manual-code-field, .order-manual-name-field, .order-date-field, .order-delivery-date-field) {
    grid-column: span 1 !important;
  }
  .app-shell #editor-view .order-creator-field {
    grid-column: 1 / -1 !important;
  }
  .app-shell #editor-view .line-main-row {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  }
  .app-shell #editor-view .line-main-row td:nth-child(1) { grid-column: span 1; grid-row: 1; }
  .app-shell #editor-view .line-main-row td:nth-child(2) { grid-column: span 5; grid-row: 1; }
  .app-shell #editor-view .line-main-row td:nth-child(3) { grid-column: span 3; grid-row: 2; }
  .app-shell #editor-view .line-main-row td:nth-child(4) { grid-column: span 3; grid-row: 2; }
  .app-shell #editor-view .line-main-row td:nth-child(5),
  .app-shell #editor-view .line-main-row td:nth-child(6),
  .app-shell #editor-view .line-main-row td:nth-child(7) { grid-column: span 2; grid-row: 3; }
  .app-shell #editor-view .line-main-row td:nth-child(8),
  .app-shell #editor-view .line-main-row td:nth-child(9) { grid-column: span 3; grid-row: 4; }
  .app-shell #editor-view .line-main-row td:nth-child(10),
  .app-shell #editor-view .line-main-row td:nth-child(11) { grid-column: span 3; grid-row: 5; }
  .app-shell #editor-view .editor-side {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .app-shell #editor-view .lines-title {
    min-height: 30px !important;
  }
  .app-shell #editor-view #lines-quick-summary {
    display: none !important;
  }
}
