/* Keep the sales readouts on a shared panel, with a gutter between hit targets. */
@media screen {
  #jp-native-root .center-shell .sf-kpis.sfm-v7 {
    --sales-group-gap: 24px;
    --sales-pair-gap: 16px;
    --sales-group-pad: 16px;
    --sales-reading-inset: 22px;
    --sales-reading-block: 16px;
    gap: var(--sales-group-gap) !important;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-group {
    padding: 20px var(--sales-group-pad) 16px !important;
    gap: 6px !important;
    min-inline-size: 0;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-group-label {
    padding-inline: var(--sales-reading-inset) !important;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair {
    gap: var(--sales-pair-gap) !important;
    align-content: center;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair > .sfm-card {
    container-type: inline-size;
    padding: var(--sales-reading-block) var(--sales-reading-inset) !important;
    border-inline: 0 !important;
    border-radius: 10px !important;
    min-inline-size: 0;
    gap: 0 !important;
    justify-content: flex-start !important;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair .sfm-heading {
    margin-bottom: 13px !important;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair .sfm-footer {
    margin: 7px 0 0 !important;
    min-inline-size: 0;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair .sfm-footer span {
    white-space: normal !important;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair .sfm-value.is-wide-number {
    font-size: clamp(16px, 11cqi, 34px) !important;
    flex-wrap: wrap;
    row-gap: 0 !important;
  }
  #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair .sfm-value.is-wide-number > data {
    font-size: clamp(16px, 11cqi, 34px) !important;
    max-inline-size: 100%;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  @media (min-width:3000px) {
    #jp-native-root .center-shell .sf-kpis.sfm-v7 {
      --sales-group-gap: 32px;
      --sales-pair-gap: 24px;
      --sales-reading-inset: 28px;
      --sales-reading-block: 18px;
    }
  }
  @media (max-width: 1599px) {
    #jp-native-root .center-shell .sf-kpis.sfm-v7 {
      --sales-group-gap: 18px;
      --sales-pair-gap: 12px;
      --sales-group-pad: 10px;
      --sales-reading-inset: 16px;
      --sales-reading-block: 12px;
    }
    #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-group {
      padding-block: 16px 10px !important;
    }
    #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-pair .sfm-heading {
      margin-bottom: 10px !important;
    }
  }
  @media (max-width: 679px) {
    #jp-native-root .center-shell .sf-kpis.sfm-v7 {
      --sales-group-gap: 16px;
      --sales-pair-gap: 10px;
      --sales-group-pad: 9px;
      --sales-reading-inset: 12px;
      --sales-reading-block: 12px;
    }
    #jp-native-root .center-shell .sf-kpis.sfm-v7 .sfm-group {
      padding-block: 15px 9px !important;
    }
  }
}

/* Pairs have a common panel and separate, padded hit targets inside that panel. */
@media screen {
  #jp-native-root .center-shell {
    --report-cell-gutter: clamp(10px, .65vw, 20px);
    --report-cell-inline: clamp(12px, .82vw, 22px);
    --report-cell-block: clamp(10px, .54vw, 16px);
  }
  #jp-native-root .center-shell .cm-summary-v7 .cm-metric-pair {
    padding: 10px var(--report-cell-gutter) 12px !important;
    gap: var(--report-cell-gutter) !important;
  }
  #jp-native-root .center-shell .cm-metric-pair > button.cm-stat,
  #jp-native-root .center-shell .ps-kpis-v7 :is(.ps-v7-pair,.ps-v7-facts) > button {
    padding: var(--report-cell-block) var(--report-cell-inline) !important;
    border-inline-start: 0 !important;
    min-width: 0;
  }
  #jp-native-root .center-shell .ps-kpis-v7 :is(.ps-v7-pair,.ps-v7-facts) {
    margin-inline: calc(-.55 * var(--report-cell-inline)) !important;
    gap: var(--report-cell-gutter) !important;
  }
  #jp-native-root .center-shell .ia-v7-current .ia-total,
  #jp-native-root .center-shell .fs-profit-summary :is(.fs-profit-value,.fs-margin) {
    padding-inline: var(--report-cell-inline) !important;
    border-radius: 10px;
  }
  #jp-native-root .center-shell .ab-channels .ab-channel {
    padding: 8px 12px !important;
  }
  /* The chart renderer resizes on its next frame. Clip only its drawing surface
     in that interval, leaving the HTML tooltip and pointer coordinates intact. */
  #jp-native-root .center-shell .ab-chart[data-chart] > div:has(> canvas) {
    max-width: 100%;
    overflow: clip;
  }
  @media (min-width: 1100px) {
    #jp-native-root .center-shell .cp-profit-pair > button {
      padding: 10px var(--report-cell-inline) !important;
      border-inline-start: 0 !important;
    }
    #jp-native-root .center-shell .cp-profit-pair {
      column-gap: var(--report-cell-gutter) !important;
    }
    #jp-native-root .center-shell .ia-v7-risks {
      gap: var(--report-cell-gutter) !important;
    }
  }
  @media (min-width: 768px) and (max-width: 1050px) {
    #jp-native-root .center-shell .cm-summary-v7 .cm-group-primary {
      grid-row: auto !important;
      grid-column: 1/-1 !important;
      display: grid !important;
      grid-template-columns: minmax(0,1.65fr) minmax(0,1fr);
      align-items: center;
    }
    #jp-native-root .center-shell .cm-summary-v7 .cm-group-primary .cm-total-stat {
      border-top: none !important;
      border-inline-start: 1px solid rgb(255 255 255 / .28);
    }
  }
  @media (max-width: 767px) {
    @layer jp-interactions {
      #jp-native-root .center-shell .ov-business-summary .ov-business-item {
        padding-inline: 16px !important;
      }
    }
    #jp-native-root .center-shell .ov-business-summary .ov-business-item {
      grid-template: auto auto / 34px minmax(0,1fr) !important;
    }
    #jp-native-root#jp-native-root .center-shell .ov-business-item .ov-business-icon {
      grid-area: 1 / 1 !important;
    }
    #jp-native-root#jp-native-root .center-shell .ov-business-item .ov-business-value {
      grid-area: 1 / 2 !important;
    }
    #jp-native-root#jp-native-root .center-shell .ov-business-item .ov-business-foot {
      grid-area: 2 / 1 / auto / -1 !important;
      margin: 0 !important;
      border-radius: 6px;
    }
  }
  @media (max-width: 540px) {
    #jp-native-root .center-shell .ps-kpis-v7 .ps-v7-facts {
      grid-template-columns: minmax(0,1fr) !important;
      gap: 6px !important;
    }
    #jp-native-root .center-shell .ps-kpis-v7 .ps-v7-facts > button {
      display: flex !important;
      flex-direction: row !important;
      align-items: center !important;
      justify-content: space-between !important;
      flex-wrap: wrap;
      gap: 5px 12px !important;
      min-height: 48px !important;
    }
    #jp-native-root .center-shell .ps-kpis-v7 .ps-v7-facts > button > strong {
      margin: 0 !important;
    }
    #jp-native-root .center-shell .ps-kpis-v7 .ps-v7-facts > button > span:first-child {
      display: inline-flex !important;
      flex-direction: row !important;
      align-items: center !important;
      width: auto !important;
      gap: 8px !important;
    }
    #jp-native-root .center-shell .ab-risks .ab-risk {
      padding-inline: 14px !important;
    }
  }
}

/* Keep report and dispatch layouts independent from the business overview cards. */
@layer jp-workspace-spacing {
  @media screen {
    html[data-page]:not([data-page="Outbound"],[data-page="Dashboard"],[data-page="BusinessReport"],[data-page="AssistantWorkspace"],[data-page$="Print"]) #jp-native-root {
      :is(.n-stats:has(> .e-metric),.v-stat-grid:has(> .e-metric),.inv-reading,
          .jp-ledger-readout,.purchase-summary,.jp-b2-supplier-overview,.original-metric-row,
          .customer-development-values,.p-payroll .p-cards) {
        @media (max-width:767px) {
          --card-space: 12px clamp(12px,3.7vw,16px);
        }
        @media (min-width:1920px) {
          --card-space: 20px 28px;
          --group-gap: 20px;
        }
      }
      /* Readout pairs use a separate nested grid in procurement and suppliers. */
      :is(.inv-reading,.jp-ledger-readout,.purchase-summary,.jp-purchase-readout,
          .jp-purchase-metrics.is-open,.jp-b2-supplier-overview) {
        @media (max-width:767px) { gap:12px !important; }
        @media (min-width:1920px) { gap:20px !important; }
      }
      @media (max-width:767px) {
        .jp-purchase-readout :is(.jp-purchase-readout-primary,.jp-purchase-readout-count) {
          display:flex !important;
          align-items:flex-start !important;
          align-content:flex-start !important;
          justify-content:flex-start !important;
          flex-flow:column nowrap !important;
        }
        /* The three long customer development labels need more than a third of a phone screen. */
        .customer-development-values {
          grid-template-columns:repeat(2,minmax(0,1fr)) !important;
          gap:10px 12px !important;
        }
        .customer-development-values > article {
          min-height:76px !important;
        }
        .customer-development-values > article:first-child {
          grid-column:1 / -1;
          flex-direction:row !important;
          display:flex !important;
          justify-content:space-between !important;
          align-items:center !important;
          min-height:54px !important;
        }
        .customer-development-values > article:first-child > strong {
          align-self:center !important;
        }
      }
      @media (min-width:768px) and (max-width:960px) {
        .customers-workspace .n-stats:has(> .e-metric:nth-child(5)) {
          grid-template-columns:repeat(6,minmax(0,1fr)) !important;
        }
        .customers-workspace .n-stats:has(> .e-metric:nth-child(5)) > .e-metric {
          grid-column:span 2 !important;
        }
        .customers-workspace .n-stats:has(> .e-metric:nth-child(5)) > .e-metric:nth-child(-n+2) {
          grid-column:span 3 !important;
        }
      }
    }
  }
}

@layer jp-workspace-spacing {
  /* Keep related choices together while leaving room between their hit areas. */
  @media screen and (min-width: 768px) {
    #jp-native-root :is(.q-page,.support-system,.mall-decoration) .n-tabs {
      gap: 8px !important;
      padding: 6px !important;
    }
  }
  @media screen and (max-width: 767px) {
    #jp-native-root .fulfillment-delivery > nav[aria-label="配送工作区"] {
      gap: 6px !important;
      padding: 6px !important;
    }
    #jp-native-root .catalog-page .n-panel-head > .n-actions {
      gap: 8px !important;
    }
  }
}
