/* Shared by full screens and quick-entry frames. Register before the control
   interaction layer so pressed selections retain readable black text. */
@layer alfares-dropdown-fields {
  :is(.my-report-select-options, .alfares-catalog-select-options, .auth-select-options) {
    overflow-y: scroll !important;
    scrollbar-gutter: stable !important;
    scrollbar-width: auto !important;
    scrollbar-color: #6b8eae #edf3f8 !important;
  }

  :is(.my-report-select-options, .alfares-catalog-select-options, .auth-select-options)::-webkit-scrollbar {
    width: 10px !important;
  }

  :is(.my-report-select-options, .alfares-catalog-select-options, .auth-select-options)::-webkit-scrollbar-track {
    border-radius: 8px !important;
    background: #edf3f8 !important;
  }

  :is(.my-report-select-options, .alfares-catalog-select-options, .auth-select-options)::-webkit-scrollbar-thumb {
    min-height: 28px !important;
    border: 2px solid #edf3f8 !important;
    border-radius: 8px !important;
    background: #6b8eae !important;
  }

  @supports selector(::-webkit-scrollbar) {
    :is(.my-report-select-options, .alfares-catalog-select-options, .auth-select-options) {
      scrollbar-color: auto !important;
    }
  }

  :is(select, option, optgroup,
      .my-report-select-button, .my-report-select-value, .my-report-select-option,
      .alfares-catalog-select-trigger, .alfares-catalog-select-value, .alfares-catalog-select-option,
      .auth-select-trigger, .auth-select-trigger > span, .auth-select-option,
      .my-report-select-search, .alfares-catalog-select-search, .auth-select-search input,
      .account-lookup-picker, [data-account-selected-text]) {
    color: #000 !important;
    -webkit-text-fill-color: #000 !important;
  }

  /* These are selection surfaces only; semantic add/delete actions and balance
     indicators keep their own colors. Portalled option lists are included. */
  :is(select, option, optgroup) {
    background-color: #fff !important;
  }

  :is(.my-report-select-button, .my-report-select-panel,
      .alfares-catalog-select-trigger, .alfares-catalog-select-menu,
      .auth-select-trigger, .auth-select-panel, .auth-select-search,
      .my-report-select-search, .alfares-catalog-select-search, .account-lookup-picker) {
    background-color: #fff !important;
    background-image: none !important;
  }

  :is(.my-report-select-option, .alfares-catalog-select-option, .auth-select-option) {
    background-color: #fff !important;
    background-image: none !important;
    box-shadow: none !important;
  }

  :is(.my-report-select-option, .alfares-catalog-select-option, .auth-select-option)
    :is(span, strong, small, b) {
    color: #000 !important;
    -webkit-text-fill-color: #000 !important;
  }

  :is(.my-report-select-option, .alfares-catalog-select-option, .auth-select-option)
    :is(svg, i) {
    -webkit-text-fill-color: currentColor !important;
  }

  :is(.my-report-select-option, .alfares-catalog-select-option, .auth-select-option):is(:disabled, [aria-disabled="true"]) {
    cursor: not-allowed;
    opacity: .58;
  }

  :is(.my-report-select-option, .alfares-catalog-select-option, .auth-select-option):is(
      :hover, :focus-visible, :active, .is-active, [aria-selected="true"]) {
    background-color: #edf3f8 !important;
    background-image: none !important;
    border-color: #9eafc0 !important;
    box-shadow: none !important;
  }

  :is(.my-report-select-button, .alfares-catalog-select-trigger, .auth-select-trigger,
      .account-lookup-picker):active {
    background-color: #edf3f8 !important;
    border-color: #9eafc0 !important;
    box-shadow: none !important;
  }

  :is(.my-report-select-button, .alfares-catalog-select-trigger, .auth-select-trigger,
      .account-lookup-picker):is(:disabled, [aria-disabled="true"]),
  select:disabled {
    background-color: #f0f2f4 !important;
  }

  /* The existing reference controls share a single border. No DOM relocation,
     event replacement, or change to the native select's value is needed. */
  .tarefat-account-picker {
    direction: inherit !important;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 0 !important;
    min-width: 0 !important;
    width: 100%;
    padding: 2px !important;
    border: 1px solid #c6d4e0 !important;
    border-radius: 9px !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker):focus-within {
    border-color: #657b91 !important;
    outline: 1px solid #657b91;
    outline-offset: 1px;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker):has(> :is(.alfares-quick-entry-field-menu-trigger,
      .items-reference-menu-trigger, .accounts-reference-menu-trigger,
      .cost-centers-inline-button, .account-lookup-more, .tarefat-account-picker__actions):not([hidden], .d-none, [aria-hidden="true"])) {
    grid-template-columns: auto minmax(0, 1fr) !important;
  }

  /* An enhanced select stays a 1px absolute element behind its combobox; a
     layered 100% width would stretch it across the screen and add a scrollbar. */
  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker) > :is(select:not(.is-enhanced), .my-document-select-combobox,
      .my-report-select-combobox, .alfares-catalog-select,
      .cost-centers-control--select, .account-lookup-picker) {
    grid-column: -2 / -1 !important;
    grid-row: 1 !important;
    min-width: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 6px !important;
    background-color: transparent !important;
    box-shadow: none !important;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field)
    :is(.my-report-select-button, .alfares-catalog-select-trigger,
        .cost-centers-control--select > select) {
    border: 0 !important;
    border-radius: 6px !important;
    box-shadow: none !important;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker) select:disabled {
    background-color: #f0f2f4 !important;
    cursor: not-allowed;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker) > :is(.alfares-quick-entry-field-menu-trigger,
      .items-reference-menu-trigger, .accounts-reference-menu-trigger,
      .cost-centers-inline-button, .account-lookup-more, .tarefat-account-picker__actions):not([hidden], .d-none, [aria-hidden="true"]) {
    grid-column: 1 !important;
    grid-row: 1 !important;
    position: relative !important;
    inset: auto !important;
    display: inline-grid !important;
    place-items: center !important;
    align-self: stretch !important;
    width: 32px !important;
    min-width: 32px !important;
    height: auto !important;
    min-height: 32px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 6px !important;
    background: #f5f7f9 !important;
    color: #000 !important;
    -webkit-text-fill-color: #000 !important;
    box-shadow: none !important;
    cursor: pointer;
    touch-action: manipulation;
  }

  /* Keep the action physically on the right for both document directions. */
  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker):dir(ltr):has(> :is(.alfares-quick-entry-field-menu-trigger,
      .items-reference-menu-trigger, .accounts-reference-menu-trigger,
      .cost-centers-inline-button, .account-lookup-more, .tarefat-account-picker__actions):not([hidden], .d-none, [aria-hidden="true"])) {
    grid-template-columns: minmax(0, 1fr) auto !important;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker):dir(ltr) > :is(select, .my-document-select-combobox,
      .my-report-select-combobox, .alfares-catalog-select,
      .cost-centers-control--select, .account-lookup-picker) {
    grid-column: 1 !important;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker):dir(ltr) > :is(.alfares-quick-entry-field-menu-trigger,
      .items-reference-menu-trigger, .accounts-reference-menu-trigger,
      .cost-centers-inline-button, .account-lookup-more, .tarefat-account-picker__actions):not([hidden], .d-none, [aria-hidden="true"]) {
    grid-column: 2 !important;
  }

  :is(.alfares-quick-entry-field-menu-trigger, .items-reference-menu-trigger,
      .accounts-reference-menu-trigger, .cost-centers-inline-button,
      .account-lookup-more, .tarefat-account-picker__actions):focus-visible {
    outline: 2px solid #657b91 !important;
    outline-offset: -2px !important;
  }

  :is(.alfares-quick-entry-field-menu-trigger, .items-reference-menu-trigger,
      .accounts-reference-menu-trigger, .cost-centers-inline-button,
      .account-lookup-more, .tarefat-account-picker__actions):disabled {
    opacity: .55;
    cursor: not-allowed;
  }

  /* Customer/supplier fields already have a shared frame and extra detail
     controls. Swap only the two edge actions, retaining their existing tracks. */
  .invoice-party-field-shell:has(> .invoice-party-menu-trigger:not([hidden], .d-none, [aria-hidden="true"]))
    > .invoice-party-menu-trigger {
    grid-column: 1 !important;
    grid-row: 1 !important;
  }

  .invoice-party-field-shell:has(> .invoice-party-menu-trigger:not([hidden], .d-none, [aria-hidden="true"]))
    > :is(.invoice-party-field-icon:not(.invoice-party-detail-field-trigger), [data-party-search-menu-button]) {
    grid-column: -2 / -1 !important;
    grid-row: 1 !important;
  }

  .invoice-party-field-shell:dir(ltr):has(> .invoice-party-menu-trigger:not([hidden], .d-none, [aria-hidden="true"]))
    > .invoice-party-menu-trigger {
    grid-column: -2 / -1 !important;
  }

  .invoice-party-field-shell:dir(ltr):has(> .invoice-party-menu-trigger:not([hidden], .d-none, [aria-hidden="true"]))
    > :is(.invoice-party-field-icon:not(.invoice-party-detail-field-trigger), [data-party-search-menu-button]) {
    grid-column: 1 !important;
  }

  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker):is([hidden], .d-none, [aria-hidden="true"]),
  :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
      .account-lookup-control, .tarefat-account-picker) > :is(.alfares-quick-entry-field-menu-trigger,
      .items-reference-menu-trigger, .accounts-reference-menu-trigger,
      .cost-centers-inline-button, .account-lookup-more, .tarefat-account-picker__actions):is([hidden], .d-none, [aria-hidden="true"]) {
    display: none !important;
  }

  @media (max-width: 1199px), (pointer: coarse) {
    :is(.alfares-quick-entry-field-control, .alfares-unified-reference-field,
        .account-lookup-control, .tarefat-account-picker) > :is(.alfares-quick-entry-field-menu-trigger,
        .items-reference-menu-trigger, .accounts-reference-menu-trigger,
        .cost-centers-inline-button, .account-lookup-more, .tarefat-account-picker__actions):not([hidden], .d-none, [aria-hidden="true"]) {
      width: 44px !important;
      min-width: 44px !important;
      min-height: 44px !important;
    }
  }
}
