/* Shared legacy/widget header actions. Keep tools in flow in both directions.
 * Deliberately screen-only: receipt/report printing retains its existing rules.
 * :has limits layout changes to headers that actually contain a tools slot.
 */
@media screen {
  .box-header:has(> .box-tools :is(a, button):not(.btn-box-tool, .close)) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
  }

  .box-header:has(> .box-tools :is(a, button):not(.btn-box-tool, .close))::before,
  .box-header:has(> .box-tools :is(a, button):not(.btn-box-tool, .close))::after {
    content: none;
  }

  .box-header:has(> .box-tools :is(a, button):not(.btn-box-tool, .close)) > .box-title {
    flex: 1 1 200px;
    min-width: 0;
    margin: 0;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }

  .box-header:has(> .box-tools :is(a, button):not(.btn-box-tool, .close)) > .box-tools {
    position: static;
    inset: auto;
    float: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    margin-inline-start: auto;
  }

  .box-header > .box-tools > :is(.pull-right, .pull-left) {
    float: none !important; /* Bootstrap's utility uses !important. */
  }

  .box-header:has(> .box-tools :is(a, button):not(.btn-box-tool, .close)) > br {
    display: none;
  }

  .box-header:has(> .box-tools :is(a, button):not(.btn-box-tool, .close)) > small {
    flex-basis: 100%;
  }

  /* Some screens use MD3 button classes without loading md3_core.css.
   * Supply their missing appearance here, without importing the whole theme.
   * Other Bootstrap/Tailwind and semantic action colors remain authoritative.
   */
  .box-header > .box-tools :is(.md3-btn-primary, .btn-primary-md3) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 8px 20px;
    border: 1px solid transparent;
    border-radius: 12px;
    background-color: #dd2229;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    text-decoration: none;
    cursor: pointer;
  }

  .box-header > .box-tools :is(.md3-btn-primary, .btn-primary-md3):hover {
    background-color: #c51c22;
    color: #fff;
    text-decoration: none;
  }

  .box-header > .box-tools :is(.btn, .tw-dw-btn, .md3-btn-primary, .md3-btn-secondary):focus-visible {
    outline: 3px solid #06133e;
    outline-offset: 3px;
  }

  .box-header > .box-tools :is(.md3-btn-primary, .btn-primary-md3):is(:disabled, .disabled, [aria-disabled="true"]) {
    opacity: 0.55;
    cursor: not-allowed;
  }
}
