/* Shared spacing fixes verified against the published desktop and mobile UI. */
@media screen {
  html:has(.app-shell, .auth-page),
  body:has(.app-shell, .auth-page) {
    min-width: 0;
  }

  .metric-card {
    min-width: 0;
  }

  .metric-card > strong {
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
  }

  .customer-card dl > div {
    display: grid;
    grid-template-columns: minmax(72px, auto) minmax(0, 1fr);
    align-items: start;
    gap: 12px;
  }

  .customer-card dd,
  .customer-card dd a {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  .customer-card header strong {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.45;
  }

  .product-card__header:has(.product-card__movements-icon) {
    grid-template-columns: 48px minmax(0, 1fr) 36px;
    column-gap: 10px;
    row-gap: 8px;
  }

  .product-card__header:has(.product-card__movements-icon) .product-card__image {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 48px;
    height: 48px;
  }

  .product-card__header:has(.product-card__movements-icon) .product-card__copy {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .product-card__movements-icon {
    grid-column: 3;
    grid-row: 1;
  }

  .product-card__header:has(.product-card__movements-icon) .product-card__edit-icon {
    grid-column: 3;
    grid-row: 2;
  }

  .product-card__stock-stat > span {
    flex-wrap: wrap;
    white-space: normal;
    line-height: 1.4;
    gap: 4px;
  }

  .page-toolbar,
  .content-toolbar {
    flex-wrap: wrap;
    row-gap: 16px;
  }

  .page-toolbar > .button,
  .page-toolbar .button-row > .button,
  .content-toolbar > .button {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .page-toolbar .button-row {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
    row-gap: 12px;
  }

  .purchases-page td[data-label="Proveedor"] {
    max-width: 250px;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  .page-content .table-subcopy {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.5;
  }

  .expenses-page td[data-label="Concepto"],
  .expenses-page td[data-label="Proveedor u organismo"] {
    max-width: 250px;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  .inventory-movements-table .inventory-movement-product {
    min-width: 220px;
    max-width: 300px;
    white-space: normal;
  }

  .inventory-movements-table__product {
    min-width: 0;
  }

  .inventory-movements-table__product strong {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 13px;
    line-height: 1.5;
  }

  .expense-toolbar {
    grid-template-columns: repeat(4, minmax(0, 1fr)) 40px max-content;
    gap: 16px;
    justify-content: stretch;
    align-items: end;
  }

  .expense-toolbar > .search-field {
    grid-column: 1 / 4;
    grid-row: 1;
    width: 100%;
    min-width: 0;
  }

  .expense-toolbar > .page-toolbar__count {
    grid-column: 4;
    grid-row: 1;
    align-self: center;
  }

  .expense-toolbar > .export-toolbar-slot {
    grid-column: 5;
    grid-row: 1;
  }

  .expense-toolbar > .button {
    grid-column: 6;
    grid-row: 1;
  }

  .expense-toolbar > .expense-filter {
    grid-row: 2;
    min-width: 0;
    width: 100%;
  }

  .expense-toolbar .expense-filter input,
  .expense-toolbar .expense-filter .select-control__trigger {
    min-width: 0;
    width: 100%;
  }

  .expense-toolbar .expense-filter > input {
    border: 1px solid var(--line);
    padding: 0 12px;
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    background: var(--surface);
  }

  .expense-toolbar .expense-filter > input:focus-visible {
    border-color: var(--action);
    outline: 3px solid rgb(67 56 202 / 16%);
    outline-offset: 2px;
  }
}

@media screen and (min-width: 621px) and (max-width: 1180px) {
  .expense-toolbar > .expense-filter:nth-of-type(2) {
    grid-column: 1 / 4;
    grid-row: 2;
  }

  .expense-toolbar > .expense-filter:nth-of-type(3) {
    grid-column: 4 / 7;
    grid-row: 2;
  }

  .expense-toolbar > .expense-filter:nth-of-type(4) {
    grid-column: 1 / 4;
    grid-row: 3;
  }

  .expense-toolbar > .expense-filter:nth-of-type(5) {
    grid-column: 4 / 7;
    grid-row: 3;
  }
}

@media screen and (max-width: 620px) {
  .page-toolbar {
    display: flex;
    flex-wrap: wrap;
  }

  .page-toolbar .button-row {
    width: 100%;
  }

  .page-toolbar .button-row > .button {
    flex: 1 1 150px;
    width: auto;
  }

  :is(.page-toolbar .search-field, .report-search) {
    right: max(64px, env(safe-area-inset-right));
    width: 42px;
  }

  :is(.page-toolbar .search-field, .report-search):focus-within {
    left: 58px;
    right: max(64px, env(safe-area-inset-right));
    width: auto;
  }
  .amount-input input {
    font-size: clamp(22px, 7vw, 32px);
  }

  .sale-payment-heading {
    flex-wrap: wrap;
    gap: 16px;
  }

  .sale-payment-heading h2 {
    flex-basis: 100%;
  }

  .sale-payment-pending-toggle {
    margin-left: auto;
  }

  .pending-filters,
  .insights-tabs {
    flex-wrap: wrap;
    gap: 8px;
    overflow: visible;
  }

  .pending-filters button,
  .insights-tabs button {
    white-space: nowrap;
  }

  .insights-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .insights-tabs button {
    justify-content: flex-start;
    width: 100%;
  }

  .expense-toolbar {
    display: flex;
    flex-wrap: wrap;
  }

  .expense-toolbar > .expense-filter {
    flex: 1 1 calc(50% - 8px);
  }

  .expense-toolbar > .page-toolbar__count {
    margin-right: auto;
  }

  .topbar__title {
    font-size: 18px;
    line-height: 1.3;
    white-space: normal;
    overflow-wrap: anywhere;
    text-overflow: clip;
  }

  .topbar {
    min-height: 60px;
    height: auto;
    padding-block: 10px;
  }

  .sale-detail-products {
    border: 0;
    border-radius: 0;
  }

  .sale-detail-products > .panel__header {
    padding: 4px 2px 16px;
    flex-wrap: wrap;
    gap: 14px;
  }

  .task-actions {
    flex-wrap: wrap;
    gap: 12px;
  }
}

@media screen and (min-width: 761px) {
  .expenses-page td[data-label="Concepto"] {
    min-width: 220px;
  }

  .expenses-page td[data-label="Proveedor u organismo"] {
    min-width: 200px;
  }
}

@media screen and (max-width: 480px) {
  .dashboard-page .metric-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .customer-business__metrics {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-page .metric-card,
  .dashboard-page .metric-card--featured {
    min-height: 0;
    padding: 20px;
  }

  .dashboard-page .metric-card__icon {
    margin-bottom: 12px;
  }

  .dashboard-page .metric-card > strong {
    font-size: clamp(22px, 7vw, 28px);
  }
}
