/* Keep the focus line inside editable fields, including clipped document cells.
   A 1px outline at -2px keeps its outer edge 1px inside the field box,
   directly beside an existing 1px border or with 1px space in borderless cells.
   Paint only: dimensions, padding, validation colours and values stay intact. */
@media screen {
  html body :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="image"]):not([type="hidden"]),
    textarea,
    select:not(.inquiry-source-trigger):not(.huihuang-header-filter-select),
    [contenteditable=""],
    [contenteditable="true"],
    [contenteditable="plaintext-only"]
  ):not(:disabled):not([readonly]):not([aria-disabled="true"]):not([aria-readonly="true"]):focus,
  html body .inquiry-manager-field > input[readonly]:not(:disabled):not([aria-disabled="true"]):focus,
  html body input[data-editable-picker="true"]:not(:disabled):not([aria-disabled="true"]):not([aria-readonly="true"]):focus,
  html body input.quick-upload-date-trigger[readonly]:not(:disabled):not([aria-disabled="true"]):focus,
  html body .tab-page button.sv-lookup:not(:disabled):not([aria-disabled="true"]):not([aria-readonly="true"]):focus,
  html body .tab-page :is(.quotation-line-table,.ed-table) > tbody > tr > td .sv-cell-lookup:not(:disabled):not([aria-disabled="true"]):focus,
  html body #page-comparison .comp-metric-box[onclick]:not(:disabled):not([aria-disabled="true"]):not([aria-readonly="true"]):focus,
  html body .inquiry-source-fixed-label:has(> select:not(:disabled):not([aria-disabled="true"]):focus),
  html body .huihuang-header-filter:has(> select:not(:disabled):not([aria-disabled="true"]):focus) {
    outline: 1px solid var(--business-accent, #315e91) !important;
    outline-offset: -2px !important;
  }

  /* Paint transparent native selectors on their visible field wrappers. */
  html body .inquiry-source-fixed-label > select.inquiry-source-trigger:focus,
  html body .huihuang-header-filter > select.huihuang-header-filter-select:focus {
    outline: none !important;
  }

  /* Replace the old blue cell glow without hiding invoice validation shadows. */
  html body .product-create-grid td input.form-input:not([readonly]):not(:disabled):not([aria-invalid="true"]):focus {
    box-shadow: none !important;
  }

  /* The editable status text already has its own inner focus line. */
  html body .status-matrix-entry .doc-status-ui:has(.status-matrix-inline-edit:focus) {
    outline: none !important;
  }
}

/* Detail states follow the control's current availability, including fields
   rendered as plain text. Let the cell own its fill so nested selectors and
   disabled inputs cannot cover it with a different background. */
@media screen {
  html body #mainWrap #tabContent .tab-page
  :is(.quotation-line-table,.erp-document-design .ed-section .ed-table,.op-document-shell .op-table)
  > tbody:not(.huihuang-detail-fill-space):not(.si-document-fill)
  > tr:not(.huihuang-detail-blank-row) > td:not([colspan]):not([data-inquiry-price-difference]) {
    background-color: #f0f3f7 !important;
  }

  html body #mainWrap #tabContent .tab-page
  :is(.quotation-line-table,.erp-document-design .ed-section .ed-table,.op-document-shell .op-table)
  > tbody:not(.huihuang-detail-fill-space):not(.si-document-fill)
  > tr:not(.huihuang-detail-blank-row) > td:not([colspan]):not([data-inquiry-price-difference]):has(
    :is(input,textarea,select):not(:disabled):not([aria-disabled="true"]):not([readonly]):not([aria-readonly="true"]),
    [data-editable-picker="true"]:not(:disabled):not([aria-disabled="true"]):not([aria-readonly="true"]),
    button.sv-cell-lookup:not(:disabled):not([aria-disabled="true"])
  ) {
    background-color: #fff !important;
  }

  html body #mainWrap #tabContent .tab-page
  :is(.quotation-line-table,.erp-document-design .ed-section .ed-table,.op-document-shell .op-table)
  > tbody:not(.huihuang-detail-fill-space):not(.si-document-fill)
  > tr:not(.huihuang-detail-blank-row) > td:not([colspan])
  :is(input:not([type]),input[type="text"],input[type="number"],input[type="search"],input[type="date"],textarea,select,button.sv-cell-lookup):not([aria-invalid="true"]) {
    background-color: transparent !important;
    border-color: transparent !important;
  }
}

/* One focus line for all field frames. Keep border widths, validation paint,
   dimensions and handlers intact; the shared inner outline above stays in use. */
@media screen {
  html body :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="image"]):not([type="hidden"]),
    textarea,
    select:not(.inquiry-source-trigger):not(.huihuang-header-filter-select),
    [contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]
  ):not(:disabled):not([aria-disabled="true"]):not([aria-invalid="true"]):not(.quotation-header-missing):focus,
  html body .tab-page :is(button.sv-lookup,button.sv-cell-lookup):not(:disabled):not([aria-disabled="true"]):not([aria-invalid="true"]):focus,
  html body #page-comparison .comp-metric-box[onclick]:not(:disabled):not([aria-disabled="true"]):not([aria-invalid="true"]):focus,
  html body .inquiry-source-fixed-label:has(> select:not(:disabled):not([aria-disabled="true"]):focus),
  html body .huihuang-header-filter:has(> select:not(:disabled):not([aria-disabled="true"]):focus) {
    border-color: transparent !important;
  }

  /* Plain readonly fields remain selectable without an editing highlight.
     Readonly pickers retain their existing keyboard/mouse focus indication. */
  html body :is(input,textarea):is([readonly],[aria-readonly="true"]):not([data-editable-picker="true"]):not(.quick-upload-date-trigger):not(.inquiry-manager-field > input):not(:disabled):not([aria-disabled="true"]):not([aria-invalid="true"]):not(.quotation-header-missing):focus {
    outline: none !important;
  }

  /* Input magnifiers share transparent hover paint in headers, query forms,
     dialogs and detail cells. Keep field backgrounds and action buttons intact. */
  html body :is(
    button.sv-master-lookup-trigger,
    button.sv-customer-lookup-trigger,
    button.wuxi-m7-master-trigger,
    button.wuxi-m7-customer-trigger,
    button.ed-picker-button,
    button.si-customer-lookup-trigger,
    button.document-select-lookup-trigger,
    button.document-region-lookup-trigger,
    button.qn-master-lookup-trigger,
    button.qwx-master-lookup-trigger,
    button.inquiry-manager-lookup,
    button.sales-invoice-scatter-lookup-trigger
  ):is(:hover,:active),
  html body button.btn.field-picker-trigger:not(.btn-primary):not(.btn-danger):not(:disabled):is(:hover,:active) {
    background: transparent !important;
  }

  /* These whole-field pickers are buttons, including ones in order dialogs
     and query headers; ordinary action and result buttons keep their focus. */
  html body :is(
    .qwx-header label > button,
    .qn-lines button.qn-pick-product,
    button.sales-invoice-scatter-manager-trigger
  ):not(:disabled):not([aria-disabled="true"]):not([aria-readonly="true"]):not([aria-invalid="true"]):focus {
    outline: 1px solid var(--business-accent, #315e91) !important;
    outline-offset: -2px !important;
    border-color: transparent !important;
  }

  /* Charge modes use inline important border colours. A transparent border
     image replaces only that paint while focus keeps the same 1px geometry. */
  html body #page-comparison .comp-metric-box[onclick]:not(:disabled):not([aria-disabled="true"]):not([aria-readonly="true"]):not([aria-invalid="true"]):focus {
    border-image: linear-gradient(transparent, transparent) 1 !important;
  }
}
